2023.9.17模拟赛
2023.9.17模拟赛
T377848 花坛 (bed)
思路
显然会有一种贪心思路,就是对于如果满足了
时空复杂度
时间复杂度:
空间复杂度:
code
#include <iostream>
#include <algorithm>
using namespace std;
const int MaxN = 1e7 + 10;
short a[MaxN];
int n, x, y, ans = 1e9;
int cnt[3];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
//freopen("bed.in", "r", stdin);
//freopen("bed.out", "w", stdout);
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1, j = 1; i <= n && j <= n; i++) {
for (j; j <= n && (cnt[1] < x || cnt[2] < y); j++) {
cnt[a[j]]++;
}
if (j <= n) {
ans = min(ans, cnt[0]);
}
cnt[a[i]]--;
}
cout << ans << endl;
return 0;
}
T377851 小花 (flower)
思路
这个题意就是说要能维护成一个
时空复杂度
时间复杂度:
空间复杂度:
code
#include <iostream>
using namespace std;
const int MaxN = 3e5 + 10;
int a[MaxN], n, t;
int C(int x, int y) {
return (x < y ? 1 : x > y ? 2 : 3);
}
void Work() {
int s = 1, op = 1, cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (C(a[i - 1], a[i]) == 3 || (C(a[i - 1], a[i]) != op && s >= i - 1)) {
cout << "NIE" << '\n';
return;
} else if (C(a[i - 1], a[i]) != op) {
op = C(a[i - 1], a[i]), cnt++, s = i;
}
}
if (cnt == 3) cout << "TAK" << '\n';
else cout << "NIE" << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
for (cin >> t >> n; t; t--) {
Work();
}
return 0;
}
T377852 下棋 (chess)
题意
首先考虑第一问,
时空复杂度
时间复杂度:
空间复杂度:
code
#include <iostream>
using namespace std;
using ll = long long;
const int MaxN = 2010, mod = 1000000007;
int a[MaxN][MaxN], n, m;
ll dp[MaxN][MaxN], cnt[MaxN][MaxN];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m, cnt[1][1] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j], dp[i][j] = -1e9;
}
}
dp[1][1] = a[1][1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (dp[i + 1][j] <= dp[i][j] + a[i + 1][j]) {
cnt[i + 1][j] = (cnt[i + 1][j] * (dp[i + 1][j] == dp[i][j] + a[i + 1][j]) + cnt[i][j]) % mod, dp[i + 1][j] = dp[i][j] + a[i + 1][j];
}
if (dp[i][j + 1] <= dp[i][j] + a[i][j + 1]) {
cnt[i][j + 1] = (cnt[i][j + 1] * (dp[i][j + 1] == dp[i][j] + a[i][j + 1]) + cnt[i][j]) % mod, dp[i][j + 1] = dp[i][j] + a[i][j + 1];
}
}
}
cout << dp[n][m] << endl << cnt[n][m] << endl;
return 0;
}