C - Triangular Relationship

题解

枚举一个数%K的值然后统计另两个

代码

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

D - All Your Paths are Different Lengths

题解

感觉自己万分智障,没切掉,被学弟吊着打呀qwq

我们连出一条边全为\(2^0\)到\(2^(r - 1)\)的链出来,\(2^r\)是L的最高位

然后我们通过增加一些点到N的边权X,使得数量为L且合法即可。。

代码

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

E - Stop. Otherwise...

题解

计数题

加和的限制相当于有几个数两个中只能出现一个

算一个dp[i][j]表示把i个数分成j段,每一段两种染色方式染色的方案数

然后枚举有多少数用来给两种方式染色,有多少数给怎么放都没事的数

如果有出现两次就不合法的数,那么就先算不存在它的排列,再算存在它一个的排列

代码

  1. #include <bits/stdc++.h>
  2. #define enter putchar('\n')
  3. #define space putchar(' ')
  4. #define pii pair<int,int>
  5. #define fi first
  6. #define se second
  7. #define mp make_pair
  8. #define MAXN 1000005
  9. #define mo 999999137
  10. #define pb push_back
  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;T f = 1;char c = getchar();
  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) out(x / 10);
  32. putchar('0' + x % 10);
  33. }
  34. const int MOD = 998244353;
  35. int fac[4005],inv[4005],invfac[4005],N,K,vis[4005],pw[4005];
  36. int dp[4005][4005];
  37. int mul(int a,int b) {
  38. return 1LL * a * b % MOD;
  39. }
  40. int inc(int a,int b) {
  41. return a + b >= MOD ? a + b - MOD : a + b;
  42. }
  43. int C(int n,int m) {
  44. if(n < m) return 0;
  45. if(n < 0 || m < 0) return 0;
  46. return mul(fac[n],mul(invfac[m],invfac[n - m]));
  47. }
  48. int fpow(int x,int c) {
  49. int res = 1,t = x;
  50. while(c) {
  51. if(c & 1) res = mul(res,t);
  52. t = mul(t,t);
  53. c >>= 1;
  54. }
  55. return res;
  56. }
  57. int main() {
  58. #ifdef ivorysi
  59. freopen("f1.in","r",stdin);
  60. #endif
  61. inv[1] = 1;pw[0] = 1;
  62. for(int i = 2 ; i <= 4000 ; ++i) {
  63. inv[i] = mul(inv[MOD % i],MOD - MOD / i);
  64. }
  65. fac[0] = invfac[0] = 1;
  66. for(int i = 1 ; i <= 4000 ; ++i) {
  67. fac[i] = mul(fac[i - 1],i);invfac[i] = mul(invfac[i - 1],inv[i]);
  68. pw[i] = mul(pw[i - 1],2);
  69. }
  70. read(K);read(N);
  71. dp[0][1] = 1;
  72. for(int i = 1 ; i <= N ; ++i) dp[i][1] = 2;
  73. dp[0][0] = 1;
  74. for(int j = 2 ; j <= K ; ++j) {
  75. int s = 1;
  76. dp[0][j] = 1;
  77. for(int i = 1 ; i <= N ; ++i) {
  78. dp[i][j] = inc(mul(s,2),dp[i][j - 1]);
  79. s = inc(s,dp[i][j - 1]);
  80. }
  81. }
  82. for(int i = 2 ; i <= 2 * K ; ++i) {
  83. int cnt = 0,t = 0,rest = 0;
  84. memset(vis,0,sizeof(vis));
  85. for(int j = 1 ; j <= K ; ++j) {
  86. if(!vis[j] && j != i - j && i - j >= 1 && i - j <= K) {vis[j] = vis[i - j] = 1;++cnt;}
  87. }
  88. if(i % 2 == 0) ++t;
  89. rest = K - cnt * 2 - t;
  90. int ans = 0;
  91. for(int j = N ; j >= 0 ; --j) {
  92. ans = inc(ans,mul(dp[j][cnt],rest ? C(N - j - 1 + rest,rest - 1) : (N - j == 0)));
  93. }
  94. if(t) {
  95. for(int j = N - 1; j >= 0 ; --j) {
  96. ans = inc(ans,mul(dp[j][cnt],rest ? C(N - 2 - j + rest,rest - 1) : (N - 1 - j == 0)));
  97. }
  98. }
  99. out(ans);enter;
  100. }
  101. return 0;
  102. }

F - Revenge of BBuBBBlesort!

题解

我们按照逆操作考虑,容易发现是1-N顺序排列

每次交换\(a_{i - 1} < a_{i} < a_{i + 1}\)使得它变成排列p

这样原始排列每次交换的时候相邻两个不会都进行操作,所以排列p如果合法的话一定是

p[i] != i p[i + 1] == i + 1 p[i + 2] != i + 2....这样的排列

所以我们只要对p排列,顺序找出区间l,r保证l + 1,l + 3...r - 1是固定不动的

然后找出剩下往左往右的点,保证往左的点是顺序的,往右的点是顺序的即可

代码

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #define enter putchar('\n')
  6. #define space putchar(' ')
  7. #define fi first
  8. #define se second
  9. #define MAXN 300005
  10. //#define ivorysi
  11. #define pii pair<int,int>
  12. using namespace std;
  13. typedef long long int64;
  14. template<class T>
  15. void read(T &res) {
  16. res = 0;char c = getchar();T f = 1;
  17. while(c < '0' || c > '9') {
  18. if(c == '-') f = -1;
  19. c = getchar();
  20. }
  21. while(c >= '0' && c <= '9') {
  22. res = res * 10 + c - '0';
  23. c = getchar();
  24. }
  25. res *= f;
  26. }
  27. template<class T>
  28. void out(T x) {
  29. if(x < 0) {putchar('-');x = -x;}
  30. if(x >= 10) out(x / 10);
  31. putchar('0' + x % 10);
  32. }
  33. int N;
  34. int p[MAXN],v[MAXN],cnt,id[MAXN],dir[MAXN];
  35. bool vis[MAXN];
  36. void Solve() {
  37. read(N);
  38. for(int i = 1 ; i <= N ; ++i) read(p[i]);
  39. int la = 1;
  40. while(1) {
  41. while(p[la] == la && la <= N) ++la;
  42. if(la > N) break;
  43. int ed = la;
  44. while(1) {
  45. if(ed <= N && ((ed - la) & 1) && p[ed] == ed) ++ed;
  46. else if(ed <= N && !((ed - la) & 1) && p[ed] != ed) ++ed;
  47. else break;
  48. }
  49. --ed;
  50. if(p[ed] == ed) --ed;
  51. if(ed == la) {puts("No");return;}
  52. cnt = 0;
  53. for(int i = la ; i <= ed ; ++i) v[++cnt] = p[i];
  54. sort(v + 1,v + cnt + 1);
  55. for(int i = 1 ; i <= cnt ; ++i) {
  56. if(v[i] != i + la - 1) {puts("No");return;}
  57. }
  58. cnt = 0;
  59. for(int i = la ; i <= ed ; i += 2) {
  60. v[++cnt] = p[i];
  61. id[p[i]] = cnt;
  62. }
  63. sort(v + 1,v + cnt + 1);
  64. for(int i = la ; i <= ed ; i += 2) {
  65. int t = lower_bound(v + 1,v + cnt + 1,p[i]) - v;
  66. if(t <= id[p[i]]) dir[i] = 0;
  67. else dir[i] = 1;
  68. }
  69. int L = 0,R = 0;
  70. for(int i = la ; i <= ed ; i += 2) {
  71. if(dir[i] == 0) {
  72. if(p[i] < L) {puts("No");return;}
  73. L = p[i];
  74. }
  75. else {
  76. if(p[i] < R) {puts("No");return;}
  77. R = p[i];
  78. }
  79. }
  80. la = ed + 1;
  81. }
  82. puts("Yes");
  83. }
  84. int main() {
  85. #ifdef ivorysi
  86. freopen("f1.in","r",stdin);
  87. #endif
  88. Solve();
  89. return 0;
  90. }

【Atcoder】ARC102 题解的更多相关文章

  1. AtCoder ExaWizards2019题解

    AtCoder ExaWizards2019题解 AtCoder (因为代码直接用模板写的,可能有点冗长) A.Regular Triangle 给你三根棍子的长度,问你能否用他们组成等边三角形. 什 ...

  2. AtCoder | ARC102 | 瞎讲报告

    目录 ARC102 前言 正文 传送链接~ ARC102 前言 实在是太菜了....写完第一题就弃疗..感觉T3好歹也是道可做题吧!!然后T2怎么又是进制拆分! 正文 A 题意 给你两个数字\(n,k ...

  3. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  4. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

  5. AT2370 Piling Up

    https://www.luogu.org/jump/atcoder/2370 题解 答案不是\(2^{2m}\)因为每轮的第一次取球可能会不够. 我们可以设\(dp[i][j]\)表示到了第\(i\ ...

  6. Triple Shift

    来源:Atcoder ARC 136 B - Triple Shift (atcoder.jp) 题解:这道题我们不可能去硬模拟(大多数这种题都不能这样去模拟的),然后我们就要去发现特性, 发现把 a ...

  7. 重修 Slope Trick(看这篇绝对够!)

    Slope Trick 算法存在十余载了,但是我没有找到多少拍手叫好的讲解 blog,所以凭借本人粗拙的理解来写这篇文章. 本文除标明外所有图片均为本人手绘(若丑见谅),画图真的不容易啊 qwq(无耻 ...

  8. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  9. AtCoder ExaWizards 2019 简要题解

    AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...

随机推荐

  1. WebService 检测到有潜在危险的 Request.Form 值

    在web.config 的 <system.web> <pages validateRequest="false" /> <httpRuntime r ...

  2. MT【111】画图估计

    评:此类方程是超越方程,一般情况下无法解出具体的解,常见手段:1.画图  2.猜根.此处可以取特殊值a=2.5,b=3.5,容易知道此时$x=2.5\in(2,3)$

  3. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  4. APIO模拟赛(HGOI20180909)

    想法:贪心. A.最大高度大的先剪 首先需要知道: 1.每个草最多剪1次 假设有个草剪了2次,显然可以放到最后一次剪得效果和剪2次的效果一样的, 为了少剪那么草最多剪去一次,从而,步数step> ...

  5. easyui的tab加载页面中的form重复提交

    http://blog.csdn.net/fxz1982/article/details/8987769 Easyui中的tabs组件以href方式加载目标页面,如果目标页面中有dialog或者win ...

  6. python 基础数据类型之str

    1.字符串去除空格 # S.strip(self, chars=None) #去除字符串两端空格# S.lstrip(self, chars=None) #去除字符串左端空格# S.rstrip(se ...

  7. Scala进阶之路-Scala特征类与unapply反向抽取

    Scala进阶之路-Scala特征类与unapply反向抽取 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Scala特征类分析 1>.Unit 答:用于定义返回值类型, ...

  8. CM记录-集群运行故障修复记录

    集群运行故障分析(空间不足.时钟误差.状态不良) 调整空间.同步时间.重启 修复后: 各个数据节点容量分布情况

  9. 图解MySQL 内连接、外连接

    2.内连接(INNER JOIN)内连接(INNER JOIN):有两种,显式的和隐式的,返回连接表中符合连接条件和查询条件的数据行.(所谓的链接表就是数据库在做查询形成的中间表).例如:下面的语句3 ...

  10. 何凯文每日一句||DAY10