本来以为是1199rated的。。仔细一看发现是1999,所以就做了一下

这场涨分很轻松啊。。。为啥又没打

等pkuwc考完我一定打一场atcoder(咕咕咕,咕咕咕,咕咕咕咕咕咕咕~)

但是其实我思维速度上真的有点不行。。。

A - Bulletin Board

输出\((N - W + 1)(N - H + 1)\)

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define MAXN 20000005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 + c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int N,H,W;
  38. void Solve() {
  39. read(N);read(H);read(W);
  40. out(1LL * (N - H + 1) * (N - W + 1));enter;
  41. }
  42. int main() {
  43. #ifdef ivorysi
  44. freopen("f1.in","r",stdin);
  45. #endif
  46. Solve();
  47. }

B - Contests

统计这三个区间的个数,输出最小值

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define MAXN 20000005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 + c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int N;
  38. int P[105],A,B;
  39. int cnt[3];
  40. void Solve() {
  41. read(N);read(A);read(B);
  42. for(int i = 1 ; i <= N ; ++i) {
  43. read(P[i]);
  44. if(P[i] <= A) ++cnt[0];
  45. else if(P[i] <= B) ++cnt[1];
  46. else cnt[2]++;
  47. }
  48. out(min(min(cnt[0],cnt[1]),cnt[2]));enter;
  49. }
  50. int main() {
  51. #ifdef ivorysi
  52. freopen("f1.in","r",stdin);
  53. #endif
  54. Solve();
  55. }

C - Alternating Path

相邻的黑白格子之间有边,答案是每个联通块里的黑白点个数乘积之和

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define MAXN 20000005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 + c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int H,W,a[405][405],cnt[2];
  38. char s[405][405];
  39. bool vis[405][405];
  40. int dx[] = {0,1,0,-1};
  41. int dy[] = {1,0,-1,0};
  42. bool in_range(int x,int y) {
  43. return x >= 1 && x <= H && y >= 1 && y <= W;
  44. }
  45. void dfs(int x,int y) {
  46. cnt[a[x][y]]++;vis[x][y] = 1;
  47. for(int k = 0 ; k < 4 ; ++k) {
  48. int tx = x + dx[k],ty = y + dy[k];
  49. if(in_range(tx,ty)) {
  50. if(!vis[tx][ty] && a[tx][ty] != a[x][y]) {
  51. dfs(tx,ty);
  52. }
  53. }
  54. }
  55. }
  56. void Solve() {
  57. read(H);read(W);
  58. for(int i = 1 ; i <= H ; i++) {
  59. scanf("%s",s[i] + 1);
  60. for(int j = 1 ; j <= W ; ++j) {
  61. if(s[i][j] == '#') a[i][j] = 1;
  62. else a[i][j] = 0;
  63. }
  64. }
  65. int64 ans = 0;
  66. for(int i = 1 ; i <= H ; ++i) {
  67. for(int j = 1 ; j <= W ; ++j) {
  68. if(!vis[i][j]) {
  69. cnt[1] = 0;cnt[0] = 0;
  70. dfs(i,j);
  71. ans += 1LL * cnt[1] * cnt[0];
  72. }
  73. }
  74. }
  75. out(ans);enter;
  76. }
  77. int main() {
  78. #ifdef ivorysi
  79. freopen("f1.in","r",stdin);
  80. #endif
  81. Solve();
  82. }

D - Nearest Card Game

先二分一个k,使得\([x - k,x + k]\)区间里的数的个数小于等于\((x + k,\infty)\)里的数,且\(k\)最大,先把\([x - k,x + k]\)这些区间里这么多数两个人分别取走

然后从这个状态暴力模拟(大于x的数不会超过两个了),使得所有的数都小于x,剩下的就是交替一个一个取了,可以用一个前缀和预处理出来

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define MAXN 100005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 + c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int N,Q;
  38. int64 A[MAXN],sum[MAXN],b[MAXN];
  39. pii Calc(int64 l,int64 r) {
  40. int a = lower_bound(A + 1,A + N + 1,l) - A;
  41. int b = upper_bound(A + 1,A + N + 1,r) - A - 1;
  42. return mp(a,b);
  43. }
  44. int64 Process(int64 x) {
  45. if(x >= A[N]) return sum[N];
  46. int64 L = 0,R = A[N];
  47. int p = lower_bound(A + 1,A + N + 1,x) - A;
  48. while(L < R) {
  49. int64 mid = (L + R + 1) >> 1;
  50. pii t = Calc(x - mid,x + mid);
  51. int rem = N - p + 1 - (t.se - p + 1);
  52. if(rem >= t.se - t.fi + 1) L = mid;
  53. else R = mid - 1;
  54. }
  55. pii t = Calc(x - L,x + L);
  56. int len = t.se - t.fi + 1;
  57. int64 res = b[N] - b[N - len];
  58. int q = N - len,h0 = t.fi - 1,h1 = t.se + 1;
  59. while(q >= h1) {
  60. res += A[q];--q;
  61. if(h1 > q && h0 < 1) break;
  62. int now;
  63. if(h1 > q) now = h0;
  64. else if(h0 < 1) now = h1;
  65. else {
  66. if(x - A[h0] <= A[h1] - x) now = h0;
  67. else now = h1;
  68. }
  69. if(now == h1) ++h1;
  70. if(now == h0) --h0;
  71. }
  72. res += sum[h0];
  73. return res;
  74. }
  75. void Solve() {
  76. read(N);read(Q);
  77. for(int i = 1 ; i <= N ; ++i) read(A[i]);
  78. for(int i = 1 ; i <= N ; ++i) {
  79. sum[i] = A[i];
  80. if(i >= 2) sum[i] += sum[i - 2];
  81. b[i] = A[i] + b[i - 1];
  82. }
  83. int64 x;
  84. for(int i = 1 ; i <= Q ; ++i) {
  85. read(x);
  86. out(Process(x));enter;
  87. }
  88. }
  89. int main() {
  90. #ifdef ivorysi
  91. freopen("f1.in","r",stdin);
  92. #endif
  93. Solve();
  94. }

E - Attack to a Tree

这个直接dp就好了,\(dp[u][j][0/1]\)表示以\(u\)为根,砍断了\(j\)条边,0表示没有电脑,1表示有电脑,dp里的值就是和u联通的联通块值最小值是多少

用一个bool数组辅助记录一下这个dp状态可不可以被达到

转移的话就是树背包,\(dp[u][j][a] + dp[v][h][b] \rightarrow dp[u][j + h][a | b]\)

然后如果有父亲的话用\(dp[u][j][0]\)和\(dp[u][j][1]\)更新\(dp[u][j + 1][0]\)

没有的话就直接记录答案就行

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define MAXN 5005
  10. #define eps 1e-10
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 + c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. struct node {
  38. int to,next;
  39. }E[MAXN * 2];
  40. int head[MAXN],sumE;
  41. bool vis[MAXN][MAXN][2],used[MAXN][2];
  42. int64 dp[MAXN][MAXN][2],A[MAXN],g[MAXN][2];
  43. int N,siz[MAXN],ans;
  44. void add(int u,int v) {
  45. E[++sumE].to = v;
  46. E[sumE].next = head[u];
  47. head[u] = sumE;
  48. }
  49. void dfs(int u,int fa) {
  50. if(A[u] < 0) {
  51. vis[u][0][1] = 1;dp[u][0][1] = A[u];
  52. }
  53. if(A[u] > 0) {
  54. vis[u][0][0] = 1;dp[u][0][0] = A[u];
  55. }
  56. for(int i = head[u] ; i ; i = E[i].next) {
  57. int v = E[i].to;
  58. if(v != fa) {
  59. dfs(v,u);
  60. }
  61. }
  62. memset(used,0,sizeof(used));
  63. siz[u] = 1;
  64. for(int i = head[u] ; i ; i = E[i].next) {
  65. int v = E[i].to;
  66. if(v != fa) {
  67. for(int j = 0 ; j <= siz[u] + siz[v] ; ++j) used[j][0] = used[j][1] = 0;
  68. for(int j = 0 ; j <= siz[u] ; ++j) {
  69. for(int a = 0 ; a <= 1 ; ++a) {
  70. if(!vis[u][j][a]) continue;
  71. for(int h = 0 ; h <= siz[v] ; ++h) {
  72. for(int b = 0 ; b <= 1 ; ++b) {
  73. if(!vis[v][h][b]) continue;
  74. if(!used[j + h][a | b]) {
  75. g[j + h][a | b] = dp[u][j][a] + dp[v][h][b];
  76. used[j + h][a | b] = 1;
  77. }
  78. else g[j + h][a | b] = min(g[j + h][a | b],dp[u][j][a] + dp[v][h][b]);
  79. }
  80. }
  81. }
  82. }
  83. for(int j = 0 ; j <= siz[u] + siz[v] ; ++j) {
  84. for(int a = 0 ; a <= 1 ; ++a) {
  85. vis[u][j][a] = used[j][a];
  86. dp[u][j][a] = g[j][a];
  87. }
  88. }
  89. siz[u] += siz[v];
  90. }
  91. }
  92. if(fa) {
  93. for(int j = siz[u] ; j >= 0 ; --j) {
  94. if(vis[u][j][1] && dp[u][j][1] < 0) {dp[u][j + 1][0] = 0;vis[u][j + 1][0] = 1;}
  95. if(vis[u][j][0]) {dp[u][j + 1][0] = 0;vis[u][j + 1][0] = 1;}
  96. }
  97. }
  98. else {
  99. for(int j = 0 ; j <= siz[u] ; ++j) {
  100. if(vis[u][j][1] && dp[u][j][1] < 0) {ans = j;break;}
  101. if(vis[u][j][0]) {ans = j;break;}
  102. }
  103. }
  104. }
  105. void Solve() {
  106. read(N);
  107. for(int i = 1 ; i <= N ; ++i) read(A[i]);
  108. int u,v;
  109. for(int i = 1 ; i < N ; ++i) {
  110. read(u);read(v);
  111. add(u,v);add(v,u);
  112. }
  113. dfs(1,0);
  114. out(ans);enter;
  115. }
  116. int main() {
  117. #ifdef ivorysi
  118. freopen("f1.in","r",stdin);
  119. #endif
  120. Solve();
  121. }

【AtCoder】AISing Programming Contest 2019的更多相关文章

  1. 【AtCoder】Yahoo Programming Contest 2019

    A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...

  2. 【AtCoder】KEYENCE Programming Contest 2019

    A - Beginning 这个年份恐怕需要+2 #include <bits/stdc++.h> #define fi first #define se second #define p ...

  3. 【AtCoder】Tenka1 Programmer Contest 2019

    Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...

  4. 【AtCoder】M-SOLUTIONS Programming Contest

    M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...

  5. 【AtCoder】Dwango Programming Contest V题解

    A - Thumbnail 题意简述:给出N个数,找出N个数中和这N个数平均值绝对值最小的数 根据题意写代码即可= = #include <bits/stdc++.h> #define f ...

  6. AtCoder AISing Programming Contest 2019 Task D. Nearest Card Game

    题目分析在代码注释里. int main() { #if defined LOCAL && !defined DUIPAI ifstream in("main.in" ...

  7. 【AtCoder】Mujin Programming Challenge 2017

    Mujin Programming Challenge 2017 A - Robot Racing 如果每个数都是一个一个间隔开的,那么答案是\(n!\) 考虑把一个数挪到1,第二个数挪到3,以此类推 ...

  8. AISing Programming Contest 2019 翻车记

    A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> ...

  9. 【AtCoder】Tenka1 Programmer Contest

    C - 4/N 列出个方程枚举解一下 #include <bits/stdc++.h> #define fi first #define se second #define pii pai ...

随机推荐

  1. link 和@import 的区别

    两者都为外部引入css的方式. 他们的区别: 1.link属于HTML标签,而@import是css提供的 2.页面被加载时候,link会同时加载,而@import引入的文件会等到页面加载完成之后再进 ...

  2. 定时器QTimer

    import sys from PyQt5.QtCore import QTimer, Qt from PyQt5.QtWidgets import QApplication, QWidget, QP ...

  3. Elastic Job入门(2) - 使用

    运维平台 elastic-job-lite-console-${version}.tar.gz可通过mvn install编译获取,下载源码,进入console目录,执行: mvn clean ins ...

  4. ubuntu下安装pdf编辑器Master PDF Editor

    在 ubuntu 上看一些 pdf 文档,自带的pdf阅读器不带编辑功能.推荐使用 master pdf editor 1. 安装QT sudo apt-get install qt-sdk 2. 下 ...

  5. Window和document的区别

    1.window 窗口对象.就是可视化区域的大小,不包含滚动条内东东. 2.document 对象,包含滚动条以外的区域

  6. 【转】PyDev Eclipse使用技巧说明

    PyDev Package Explorer 创建项目 在开展工作之前,需要创建一个新的项目.在 Eclipse 菜单栏中,选择 File > New > Project > Pyd ...

  7. python2和3使用pip时的问题

    win10,电脑之前装有Anaconda,python2.因为需要用到python3,所以直接下载安装了python3.python3默认路径在c盘.我将其移到D盘并修改了两个环境变量.这时电脑的默认 ...

  8. VS "以下文件中的行尾不一致,要将行尾标准化吗?"

    原文地址:http://www.cnblogs.com/yymn/p/6852857.html 这是由Windows和Unix不同的标准引起的...即“回车”和“换行”的问题... “回车”和“换行” ...

  9. python语法小应用---列表和元组

    声明:本文章为参考总结CSDN上知识点所获,只是用来总结自己学习而用,如有侵权,会删除! 列表(list): 列表就像一个线性容器,但是比C++的 lis t扩展多得多 列表里的元素可以是相同类型,也 ...

  10. ocos2d-x 3.0坐标系详解--透彻篇 ---- convertToWorldSpace:把基于当前节点的本地坐标系下的坐标转换到世界坐标系中。

    convertToWorldSpace:把基于当前节点的本地坐标系下的坐标转换到世界坐标系中.重点说明:基于...   不一定要是真实的,  convertToWorldSpace 的结果也只是一个新 ...