比赛链接:Here

835A. Key races

理解题意,然后根据情况输出

835B. The number on the board

根据题目意思贪心处理下,总和和k的关系,问你要改几位,改成9就好了啊

  1. const int N = 100000 + 10;
  2. int a[N];
  3. bool cmp(int a, int b) {return a > b;}
  4. int main() {
  5. cin.tie(nullptr)->sync_with_stdio(false);
  6. ll k; string s;
  7. cin >> k >> s;
  8. int n = int(s.size());
  9. int cnt = 0;
  10. for (int i = 0; i < n; i++) {
  11. cnt += s[i] - '0';
  12. a[i] = 9 - (s[i] - '0');
  13. }
  14. sort(a, a + n, cmp);
  15. for (int i = 1; i < n; i++) a[i] += a[i - 1];
  16. if (cnt >= k) cout << "0";
  17. else {
  18. int ans = k - cnt;
  19. for (int i = 0; i < n; ++i) {
  20. if (a[i] >= ans) {
  21. cout << i + 1;
  22. break;
  23. }
  24. }
  25. }
  26. }

835C. Star sky

尝试写转移方程,但发现没必要那么麻烦,考虑二/三维前缀和,由于坐标范围在 Codeforces Round #427 (Div. 2) (A~C) - 图1 之间那么写暴力也没事

  1. const int N = 110;
  2. int sum[N][N][12];
  3. int main() {
  4. cin.tie(nullptr)->sync_with_stdio(false);
  5. int n, q, c;
  6. cin >> n >> q >> c;
  7. for (int i = 1; i <= n; ++i) {
  8. int x, y, s;
  9. cin >> x >> y >> s;
  10. sum[x][y][s] += 1;
  11. }
  12. for (int i = 1; i <= 100; ++i)
  13. for (int j = 1; j <= 100; ++j)
  14. for (int k = 0; k <= c; k++)
  15. sum[i][j][k] += sum[i - 1][j][k] + sum[i][j - 1][k] - sum[i - 1][j - 1][k];
  16. while (q--) {
  17. int t, sx, sy, ex, ey;
  18. cin >> t >> sx >> sy >> ex >> ey;
  19. int ans = 0;
  20. for (int i = 0; i <= c; ++i) {
  21. int x = (i + t) % (c + 1);
  22. ans += x * (sum[ex][ey][i] - sum[sx - 1][ey][i] - sum[ex][sy - 1][i] + sum[sx - 1][sy - 1][i]);
  23. // cout << "demo: " << ans << "\n";
  24. }
  25. cout << ans << "\n";
  26. }
  27. }