A - Thumbnail

题意简述:给出N个数,找出N个数中和这N个数平均值绝对值最小的数

根据题意写代码即可= =

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define MAXN 205
  11. #define eps 1e-8
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;char c = getchar();T f = 1;
  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,a[MAXN],s;
  38. void Solve() {
  39. read(N);
  40. s = 0;
  41. for(int i = 0 ; i < N ; ++i) {read(a[i]);s += a[i];}
  42. int t = 0;
  43. for(int i = 1 ; i < N ; ++i) {
  44. if(abs(a[i] * N - s) < abs(a[t] * N - s)) t = i;
  45. }
  46. out(t);enter;
  47. }
  48. int main() {
  49. #ifdef ivorysi
  50. freopen("f1.in","r",stdin);
  51. #endif
  52. Solve();
  53. }

B - Sum AND Subarrays

题意简述:给定N个数,子序列\([l,r]\)的美丽值定义为\(\sum_{i = l}^{r} a_{i}\),求选出\(K\)个子序列使它们美丽值的按位与最大

把\(\frac{N(N - 1)}{2}\)个数找出来,从大到小枚举每一位,如果这一位是1的个数超过K个,就把这一位是0的数全部删除,进行下一次枚举

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef double db;
  15. template<class T>
  16. void read(T &res) {
  17. res = 0;char c = getchar();T f = 1;
  18. while(c < '0' || c > '9') {
  19. if(c == '-') f = -1;
  20. c = getchar();
  21. }
  22. while(c >= '0' && c <= '9') {
  23. res = res * 10 + c - '0';
  24. c = getchar();
  25. }
  26. res *= f;
  27. }
  28. template<class T>
  29. void out(T x) {
  30. if(x < 0) {x = -x;putchar('-');}
  31. if(x >= 10) {
  32. out(x / 10);
  33. }
  34. putchar('0' + x % 10);
  35. }
  36. int N,K;
  37. int64 a[1005],s[1005];
  38. vector<int64> v,tmp;
  39. void Solve() {
  40. read(N);read(K);
  41. for(int i = 1 ; i <= N ; ++i) {
  42. read(a[i]);
  43. s[i] = s[i - 1] + a[i];
  44. }
  45. for(int i = 1 ; i <= N ; ++i) {
  46. for(int j = i ; j <= N ; ++j) {
  47. v.pb(s[j] - s[i - 1]);
  48. }
  49. }
  50. int64 ans = 0;
  51. for(int i = 40 ; i >= 0 ; --i) {
  52. tmp.clear();
  53. for(auto t : v) {
  54. if(t >> i & 1) tmp.pb(t);
  55. }
  56. if(tmp.size() >= K) {
  57. ans |= (1LL << i);
  58. v.clear();v = tmp;
  59. }
  60. }
  61. out(ans);enter;
  62. }
  63. int main() {
  64. #ifdef ivorysi
  65. freopen("f1.in","r",stdin);
  66. #endif
  67. Solve();
  68. }

C - k-DMC

题面简述:给出N长的字符串,求长度为3,序列为\(a < b < c\)满足\(s[a] = D,s[b] = M,s[c] = C\),且满足\(c - a < k\) 多组询问k

从后往前维护一个单调队列维护C,由于我们每次遇到一个M,会把队列里所有的C都+1,那我们标记就不下放,每次新来一个C初始值设成标记的相反数即可

遇到一个D把C的坐标离D超过K的全部删除,然后队列里的总和即是这个D的贡献

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define MAXN 1000005
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;char c = getchar();T f = 1;
  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. char s[MAXN];
  38. int N,Q,K;
  39. int val[MAXN],add;
  40. int que[MAXN],ql,qr;
  41. void Solve() {
  42. read(K);
  43. ql = 1;qr = 0;
  44. add = 0;
  45. int64 sum = 0,ans = 0;
  46. for(int i = N ; i >= 1 ; --i) {
  47. if(s[i] == 'C') {que[++qr] = i;val[i] = -add;sum += val[i];}
  48. else if(s[i] == 'M') ++add;
  49. else if(s[i] == 'D'){
  50. while(ql <= qr && que[ql] - i >= K) {sum -= val[que[ql++]];}
  51. if(ql <= qr) {
  52. ans += sum + 1LL * add * (qr - ql + 1);
  53. }
  54. }
  55. }
  56. out(ans);enter;
  57. }
  58. int main() {
  59. #ifdef ivorysi
  60. freopen("f1.in","r",stdin);
  61. #endif
  62. read(N);
  63. scanf("%s",s + 1);
  64. read(Q);
  65. while(Q--) {
  66. Solve();
  67. }
  68. }

D - Square Rotation

题意简述:一个平面上N个点,每次可以选一个边长为\(D\)的整点正方形(整点可以有玩具也可以没有),每次可以使坐落在整点的玩具到这个正方形顺时针的下一个,这个操作可以做任意次,要求最小化进行任意次操作后点横纵坐标差值的绝对值的最大值

只想出了500算法QAQ

我们考虑每个点\((x,y)\)可以转成\((x % D,y % D)\),然后变成等价的一堆点,只不过需要隔\(D\)排开

左下角只能是\((0,0)\)到\((D - 1,D - 1)\)

考虑一个矩形边长为\(aD + b\),以左下角在\((0,0)\)为例

对于\(A_{i,j}\)表示\(x % D == i\)且\(y % D == j\)的点的个数

对于\(i,j <= b\)能被覆盖的点是\((a + 1)^2\)

对于\(i,j > b\)能被覆盖的点是\(a^2\)

其余情况都是\(a(a + 1)\)

显然考虑一下,我们的\(a\)必须是\((a + 1)^2 >= max(A_{i,j})\)

然后对于\(aD + D - 1\)一定能覆盖所有点,所以只要考虑\(b\)就好了

我们从(0,0)开始,计算最小的合法的\(b\),然后再枚举剩余的点作为左下的点,如果能从当前的\(b\)减小则减小,不行则跳出,由于\(b\)最多减小\(D\)次,复杂度是\(O(D^2)\)的

那么对于一个左下的点\(x,y\)怎么判断\(aD + b\)是否能构成一个合法的矩形呢

我们把有值的\(A_{i,j}\)挑出来,然后把\(a^2 <A_{i,j} <= a(a + 1)\)的位置在一个二维数组里加上1,把\(a(a + 1) < A_{i,j} <= (a + 1)^2\)的位置在另一个二维数组里加上1,维护成前缀和

查询的时候看看\(a^2 <A_{i,j} <= a(a + 1)\)在没在出现\(a^2\)的地方出现

和\(a(a + 1) < A_{i,j} <= (a + 1)^2\)在没在出现\(a^2\)和\(a(a + 1)\)的地方出现

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef double db;
  15. template<class T>
  16. void read(T &res) {
  17. res = 0;char c = getchar();T f = 1;
  18. while(c < '0' || c > '9') {
  19. if(c == '-') f = -1;
  20. c = getchar();
  21. }
  22. while(c >= '0' && c <= '9') {
  23. res = res * 10 + c - '0';
  24. c = getchar();
  25. }
  26. res *= f;
  27. }
  28. template<class T>
  29. void out(T x) {
  30. if(x < 0) {x = -x;putchar('-');}
  31. if(x >= 10) {
  32. out(x / 10);
  33. }
  34. putchar('0' + x % 10);
  35. }
  36. int cnt[1005][1005],N,D,a;
  37. int s2[1005][1005],s3[1005][1005];
  38. int sum2(int x1,int y1,int x2,int y2) {
  39. if(x1 > x2 || y1 > y2) return 0;
  40. ++x1,++y1,++x2,++y2;
  41. return s2[x2][y2] - s2[x2][y1 - 1] - s2[x1 - 1][y2] + s2[x1 - 1][y1 - 1];
  42. }
  43. int sum3(int x1,int y1,int x2,int y2) {
  44. if(x1 > x2 || y1 > y2) return 0;
  45. ++x1,++y1,++x2,++y2;
  46. return s3[x2][y2] - s3[x2][y1 - 1] - s3[x1 - 1][y2] + s3[x1 - 1][y1 - 1];
  47. }
  48. bool check2(int x,int y,int b) {
  49. int d1 = sum2(max(0,b + x - D + 1),max(0,b + y - D + 1),x - 1,y - 1);
  50. int d2 = sum2(x + b + 1,y + b + 1,D - 1,D - 1);
  51. int d3 = sum2(max(0,b + x - D + 1),y + b + 1,x - 1,D - 1);
  52. int d4 = sum2(x + b + 1,max(0,b + y - D + 1),D - 1,y - 1);
  53. return !d1 && !d2 && !d3 && !d4;
  54. }
  55. bool check3(int x,int y,int b) {
  56. int d1 = sum3(x + b + 1,0,D - 1,D - 1);
  57. int d2 = sum3(0,y + b + 1,D - 1,D - 1);
  58. int d3 = sum3(max(0,b + x - D + 1),0,x - 1,D - 1);
  59. int d4 = sum3(0,max(0,b + y - D + 1),D - 1,y - 1);
  60. return !d1 && !d2 && !d3 && !d4;
  61. }
  62. void Solve() {
  63. read(N);read(D);
  64. int x,y;
  65. for(int i = 1 ; i <= N ; ++i) {
  66. read(x);read(y);
  67. cnt[x % D][y % D]++;
  68. }
  69. int t = 0;
  70. for(int i = 0 ; i < D ; ++i) {
  71. for(int j = 0 ; j < D ; ++j) {
  72. if(cnt[i][j]) {
  73. t = sqrt(cnt[i][j]);
  74. if(t * t < cnt[i][j]) ++t;
  75. a = max(t - 1,a);
  76. }
  77. }
  78. }
  79. for(int i = 0 ; i < D ; ++i) {
  80. for(int j = 0 ; j < D ; ++j) {
  81. if(cnt[i][j] > a * a && cnt[i][j] <= a * (a + 1)) s2[i + 1][j + 1]++;
  82. else if(cnt[i][j] > a * (a + 1)) s3[i + 1][j + 1]++;
  83. }
  84. }
  85. for(int i = 1 ; i <= D ; ++i) {
  86. for(int j = 1 ; j <= D ; ++j) {
  87. s2[i][j] = s2[i][j] + s2[i - 1][j] + s2[i][j - 1] - s2[i - 1][j - 1];
  88. s3[i][j] = s3[i][j] + s3[i - 1][j] + s3[i][j - 1] - s3[i - 1][j - 1];
  89. }
  90. }
  91. int b;
  92. for(b = 0 ; b < D ; ++b) {
  93. if(check2(0,0,b) && check3(0,0,b)) break;
  94. }
  95. for(int i = 0 ; i < D ; ++i) {
  96. for(int j = 0 ; j < D ; ++j) {
  97. if(!(i + j)) continue;
  98. while(b) {
  99. if(check2(i,j,b - 1) && check3(i,j,b - 1)) --b;
  100. else break;
  101. }
  102. }
  103. }
  104. out(a * D + b);enter;
  105. }
  106. int main() {
  107. #ifdef ivorysi
  108. freopen("f1.in","r",stdin);
  109. #endif
  110. Solve();
  111. }

E - Cyclic GCDs

题意简述:给定N个数,对于它的一个置换(也就是一个排列\(P_i\),相当于\(i\)可以走到\(P_i\),最后会形成若干环),每个置换的价值是每个环中最小值的乘积,求所有置换价值的最小公约数取模998244353

这题真的,过于神仙QAQ

思路清晰,结论显然,代码好写,完全就是虐我这种没有智商的蒟蒻的

显然我们要把点排序,这样的话我们每次建立环的时候第一次遇到的点一定是要被乘起来的

我们考虑一个\(DP[i][j]\)表示考虑了排序后的前\(i\)个点,然后建了\(j\)个环的价值(有点像第一类斯特林数啊)

然后\(b_i =DP[N][i]\)

考虑转移有\(i * DP[i][j] \rightarrow DP[i + 1][j]\)表示把第\(i + 1\)个点放到原先存在的圈中

\(a_{i + 1} * DP[i][j] \rightarrow DP[i + 1][j + 1]\)表示把第\(i + 1\)个点自成一圈

然后用一点生成函数的小知识显然可以得到

\(P_{i + 1}(x) = (a_{i + 1}x + i)P_{i}(x)\)

\(P_{0}(x) = 1\)

然后就可以得到\(P_{n}(x) = (a_{1}x + 0)(a_{2}x + 1)(a_{3}x + 2)...(a_{n}x + n - 1)\)

然后我们需要开个脑洞,再证个结论

\(c(P)\)表示多项式\(P\)每个系数的最大公约数

那么\(c(PQ) = c(P)c(Q)\)

为什么呢,可以这么想,首先\(c(P)c(Q)\)一定是\(c(PQ)\)所有系数的一个约数,我们把这些约数都除掉,现在我们要证明\(c(P) = c(Q) = 1\)的时候,满足\(c(PQ) = 1\)

如果\(P\)是\(k\)项,\(Q\)是\(m\)项

那么一定可以得到\(PQ\)的第一项是

\(r_{k}s_{m}x^{k + m}\)

然后如果\(c(PQ)\)有一个质因子是\(p\)

那么\(r_{k}\)和\(s_{m}\)中至少有一个是\(p\)的倍数

如果\(r_{k}\)是\(p\)的倍数,那么我们把\(r_{k}x^k\)从\(P\)中删去(因为我相当于用\(r_{k}x^{k}\)进行一次暴力卷积又对\(p\)取模)

\(s_{m}\)是\(p\)的倍数同理

然后就变成了\(\prod_{i = 1}^{n} gcd(a_{i},i - 1)\)

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define MAXN 100005
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;char c = getchar();T f = 1;
  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. const int MOD = 998244353;
  38. int N,A[MAXN];
  39. int inc(int a,int b) {
  40. return a + b >= MOD ? a + b - MOD : a + b;
  41. }
  42. int mul(int a,int b) {
  43. return 1LL * a * b % MOD;
  44. }
  45. int gcd(int a,int b) {
  46. return b == 0 ? a : gcd(b,a % b);
  47. }
  48. void Solve() {
  49. read(N);
  50. for(int i = 1 ; i <= N ; ++i) read(A[i]);
  51. sort(A + 1,A + N + 1);
  52. int ans = 1;
  53. for(int i = 1 ; i <= N ; ++i) ans = mul(ans,gcd(A[i],i - 1));
  54. out(ans);enter;
  55. }
  56. int main() {
  57. #ifdef ivorysi
  58. freopen("f1.in","r",stdin);
  59. #endif
  60. Solve();
  61. }

【AtCoder】Dwango Programming Contest V题解的更多相关文章

  1. AtCoder Dwango Programming Contest V E

    题目链接:https://dwacon5th-prelims.contest.atcoder.jp/tasks/dwacon5th_prelims_e 题目描述: 给定一个大小为\(N\)的数组\(A ...

  2. Atcoder Dwango Programming Contest V

    模拟,做了ABC三题. D难一些,就不会了. 中规中矩的吧... Atcoder DPCV B 题意:给一个序列,求出所有的子串和中AND值最大的k个数的AND. 思路:既然要求AND,那么肯定按位考 ...

  3. AtCoder [Dwango Programming Contest V] E 动态规划 多项式

    原文链接 https://www.cnblogs.com/zhouzhendong/p/AtCoder-Dwango-Programming-Contest-V-E.html 题意 有 $n$ 个数, ...

  4. Dwango Programming Contest V 翻车记

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

  5. atcoder Keyence Programming Contest 2020 题解

    比赛地址 A 题意:给一个\(n*m\)的初始为白色的矩阵,一次操作可以将一行或一列染成 黑色,问至少染出\(k\)个黑点的最少操作次数. \(n\),\(m\)<=100,\(k\)<= ...

  6. [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

    [AtCoder] NIKKEI Programming Contest 2019   本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...

  7. [AtCoder] Yahoo Programming Contest 2019

    [AtCoder] Yahoo Programming Contest 2019   很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...

  8. M-SOLUTIONS Programming Contest 2020 题解

    M-SOLUTIONS Programming Contest 2020 题解 目录 M-SOLUTIONS Programming Contest 2020 题解 A - Kyu in AtCode ...

  9. Atcoder Yahoo Programming Contest 2019 简要题解

    A-C 直接放代码吧. A int n,k; int main() { n=read();k=read(); puts(k<=(n+1)/2?"YES":"NO&q ...

随机推荐

  1. 【刷题】BZOJ 3033 太鼓达人

    Description 七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行.这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员XLk.Poet_shy和ly ...

  2. jQuery源码之 empty与html('')的区别

    empty: function() { var elem, i = 0; for ( ; (elem = this[i]) != null; i++ ) { // Remove element nod ...

  3. java基础基础总结----- System

    常用的方法: 细节分析:

  4. 「Vue」登陆-路由拦截器

    1.main.js设置拦截器 router.beforeEach(function (to,from,next) { if (to.meta.requireAuth) { if (store.stat ...

  5. Python微信红包算法

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  6. Tomcat get 中文乱码

    乱码问题 原因: tomcat默认的在url传输时是用iso8859-1编码. 解决方案一: 在使用get传输参数时,将参数中的中文转换成url格式,也就是使用urlEncode和urlDecode来 ...

  7. [转载]Juicer – 一个Javascript模板引擎的实现和优化

    http://ued.taobao.org/blog/2012/04/juicer-%E4%B8%80%E4%B8%AAjavascript%E6%A8%A1%E6%9D%BF%E5%BC%95%E6 ...

  8. python爬虫-图片批量下载

    # 爬起摄图网的图片批量下载# coding:utf-8 import requests from bs4 import BeautifulSoup from scipy.misc import im ...

  9. 什么是BS,BS和CS的区别有哪些

    BS和CS的区别以及优缺点 C/S又称Client/Server或客户/服务器模式.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.Informix或 ...

  10. 安装odbc驱动

    1.下载对应的驱动 (32位/64位) http://www.oracle.com/technetwork/database/database-technologies/instant-client/ ...