A
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
int res = 0;
for (int i = 0; i < n; ++i) {
int val;
cin >> val;
if (val > 90 && val < 180) res++;
}
cout << res << "\n";
return 0;
}
B
极限情况分析最大数91009 ^ {100}9100, 因此需要高精度运算
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
const int N = 250;
int n;
char str[N];
bool check() {
for (int i = 0; i < n; ++i) if (str[i] != '0') return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
char c;
vector<int> nums;
int ptr = 0;
while (cin >> c, c != 'e') {
if (c == '.') {
ptr = n - 1;
continue;
}
str[n++] = c;
}
int val;
cin >> val;
ptr += val;
if (check()) {
cout << 0 << "\n";
return 0;
}
if (n == 2 && str[0] == '1' && str[1] == '0' && ptr == 0) {
cout << 1 << "\n";
return 0;
}
int i = 0;
if (str[0] == '0' && ptr > 0) i++;
for (; i < n; ++i) {
cout << str[i];
if (i == ptr && ptr != n - 1) cout << '.';
}
while (ptr >= n) cout << 0, n++;
return 0;
}
C
计算最大分数以及总分数能被k+1k + 1k+1整除
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 110, M = 11, INF = 0x3f3f3f3f;
int n, m, k;
int w[N][N];
int f[N][N][M];
PII fa[N][N][M];
int get(int val) {
return (val % k + k) % k;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
k++;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
char c;
cin >> c;
w[i][j] = c - '0';
}
}
memset(f, -0x3f, sizeof f);
for (int i = 1; i <= m; ++i) f[1][i][get(w[1][i])] = w[1][i];
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
for (int r = 0; r < k; ++r) {
int val1 = -INF, val2 = -INF;
int tmp = w[i][j];
if (j - 1 >= 1) val1 = f[i - 1][j - 1][get(r - tmp)];
if (j + 1 <= m) val2 = f[i - 1][j + 1][get(r - tmp)];
if (val1 > val2) {
f[i][j][r] = val1 + tmp;
fa[i][j][r] = {
i - 1, j - 1};
}
else {
f[i][j][r] = val2 + tmp;
fa[i][j][r] = {
i - 1, j + 1};
}
}
}
}
int res = -INF, r = n, c = 1;
for (int i = 1; i <= m; ++i) {
if (f[n][i][0] > res) {
res = f[n][i][0];
c = i;
}
}
if (res < -INF / 2) cout << -1 << "\n";
else {
cout << res << "\n";
cout << c << "\n";
string str;
int curr = 0;
while (r >= 1 && c >= 1) {
auto [_r, _c] = fa[r][c][curr];
if (_c + 1 == c) str += 'L';
else if (_c - 1 == c) str += 'R';
curr = get(curr - w[r][c]);
r = _r, c = _c;
}
cout << str << "\n";
}
return 0;
}

京公网安备 11010502036488号