0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

USACO 2021 December Contest (Bronze)

This commit is contained in:
Baoshuo Ren 2021-12-22 17:03:40 +08:00
parent dc4783bc4d
commit 3d1f4438b6
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
3 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
int n;
long long ans;
char c;
std::vector<int> g, h;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
g.push_back(0);
h.push_back(0);
for (int i = 1; i <= n; i++) {
cin >> c;
if (c == 'G') {
g.push_back(i);
} else {
h.push_back(i);
}
}
g.push_back(n + 1);
h.push_back(n + 1);
for (int i = 1; i < h.size() - 1; i++) {
ans += 1ll * (h[i] - h[i - 1]) * (h[i + 1] - h[i]) - 3;
if (h[i] == h[i - 1] + 1) ans++;
if (h[i] == h[i + 1] - 1) ans++;
}
for (int i = 1; i < g.size() - 1; i++) {
ans += 1ll * (g[i] - g[i - 1]) * (g[i + 1] - g[i]) - 3;
if (g[i] == g[i - 1] + 1) ans++;
if (g[i] == g[i + 1] - 1) ans++;
}
cout << ans << endl;
return 0;
}

View File

@ -0,0 +1,27 @@
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int n, x, a[100005], b[100005], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> x;
a[i] -= x;
if (a[i] < 0) {
b[i] = -a[i];
a[i] = 0;
}
if (a[i] > a[i - 1]) ans += a[i] - a[i - 1];
if (b[i] > b[i - 1]) ans += b[i] - b[i - 1];
}
cout << ans << endl;
return 0;
}

View File

@ -0,0 +1,34 @@
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
int t, n, k, ans;
std::string g[55];
void dfs(int x, int y, int cnt, int from) {
if (x < 0 || x >= n || y < 0 || y > n || cnt > k || g[x][y] == 'H') return;
if (x == n - 1 && y == n - 1) {
ans++;
return;
}
dfs(x + 1, y, cnt + (from == 2), 1);
dfs(x, y + 1, cnt + (from == 1), 2);
}
int main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
ans = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> g[i];
}
dfs(0, 0, 0, 0);
cout << ans << endl;
}
return 0;
}