为啥最近都没有arc啊...

A - Favorite Sound

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <stack>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #define ll long long
  14. #define inf 0x3f3f3f3f
  15. #define il inline
  16. namespace io {
  17. #define in(a) a = read()
  18. #define out(a) write(a)
  19. #define outn(a) out(a), putchar('\n')
  20. #define I_int ll
  21. inline I_int read() {
  22. I_int x = 0, f = 1;
  23. char c = getchar();
  24. while (c < '0' || c > '9') {
  25. if (c == '-') f = -1;
  26. c = getchar();
  27. }
  28. while (c >= '0' && c <= '9') {
  29. x = x * 10 + c - '0';
  30. c = getchar();
  31. }
  32. return x * f;
  33. }
  34. char F[200];
  35. inline void write(I_int x) {
  36. if (x == 0) return (void) (putchar('0'));
  37. I_int tmp = x > 0 ? x : -x;
  38. if (x < 0) putchar('-');
  39. int cnt = 0;
  40. while (tmp > 0) {
  41. F[cnt++] = tmp % 10 + '0';
  42. tmp /= 10;
  43. }
  44. while (cnt > 0) putchar(F[--cnt]);
  45. }
  46. #undef I_int
  47. }
  48. using namespace io;
  49. using namespace std;
  50. #define N 100010
  51. int a, b, c;
  52. int main() {
  53. in(a), in(b), in(c);
  54. printf("%d\n", min(b / a, c));
  55. }

B - K-th Common Divisor

显然,就是求gcd的第k小的因子。

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <stack>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #define ll long long
  14. #define inf 0x3f3f3f3f
  15. #define il inline
  16. namespace io {
  17. #define in(a) a = read()
  18. #define out(a) write(a)
  19. #define outn(a) out(a), putchar('\n')
  20. #define I_int ll
  21. inline I_int read() {
  22. I_int x = 0, f = 1;
  23. char c = getchar();
  24. while (c < '0' || c > '9') {
  25. if (c == '-') f = -1;
  26. c = getchar();
  27. }
  28. while (c >= '0' && c <= '9') {
  29. x = x * 10 + c - '0';
  30. c = getchar();
  31. }
  32. return x * f;
  33. }
  34. char F[200];
  35. inline void write(I_int x) {
  36. if (x == 0) return (void) (putchar('0'));
  37. I_int tmp = x > 0 ? x : -x;
  38. if (x < 0) putchar('-');
  39. int cnt = 0;
  40. while (tmp > 0) {
  41. F[cnt++] = tmp % 10 + '0';
  42. tmp /= 10;
  43. }
  44. while (cnt > 0) putchar(F[--cnt]);
  45. }
  46. #undef I_int
  47. }
  48. using namespace io;
  49. using namespace std;
  50. #define N 100010
  51. int a, b, k, d[N], tot;
  52. int main() {
  53. in(a), in(b), in(k);
  54. int g = __gcd(a, b);
  55. for(int i = 1; i * i <= g; ++i) {
  56. if(g % i == 0) {
  57. d[++tot] = i;
  58. if(g / i != i) d[++tot] = g / i;
  59. }
  60. }
  61. sort(d+1, d + tot + 1); reverse(d + 1, d + tot + 1);
  62. printf("%d\n", d[k]);
  63. }

C - Unification

栈的经典题。。。

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <stack>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #define ll long long
  14. #define inf 0x3f3f3f3f
  15. #define il inline
  16. namespace io {
  17. #define in(a) a = read()
  18. #define out(a) write(a)
  19. #define outn(a) out(a), putchar('\n')
  20. #define I_int ll
  21. inline I_int read() {
  22. I_int x = 0, f = 1;
  23. char c = getchar();
  24. while (c < '0' || c > '9') {
  25. if (c == '-') f = -1;
  26. c = getchar();
  27. }
  28. while (c >= '0' && c <= '9') {
  29. x = x * 10 + c - '0';
  30. c = getchar();
  31. }
  32. return x * f;
  33. }
  34. char F[200];
  35. inline void write(I_int x) {
  36. if (x == 0) return (void) (putchar('0'));
  37. I_int tmp = x > 0 ? x : -x;
  38. if (x < 0) putchar('-');
  39. int cnt = 0;
  40. while (tmp > 0) {
  41. F[cnt++] = tmp % 10 + '0';
  42. tmp /= 10;
  43. }
  44. while (cnt > 0) putchar(F[--cnt]);
  45. }
  46. #undef I_int
  47. }
  48. using namespace io;
  49. using namespace std;
  50. #define N 100010
  51. char s[N];
  52. int n, st[N];
  53. int main() {
  54. scanf("%s", s + 1);
  55. n = strlen(s + 1);
  56. int ans = 0, top = 0;
  57. for(int i = 1; i <= n; ++i) s[i] -= '0';
  58. for(int i = 1; i <= n; ++i) {
  59. if(top && s[top] ^ s[i]) {++ans, --top; continue;}
  60. s[++top] = s[i];
  61. }
  62. printf("%d\n", ans * 2);
  63. }

D - Decayed Bridges

正着计数太麻烦了。

考虑最后一条边断掉之后答案肯定是\(n(n-1)/2\)。

用个经典的套路,把删边弄成倒着连边。

那么每次多连一条边,联通的点数就多了\(siz_x*siz_y\)

用\(n(n-1)/2\)减去\(siz_x*siz_y\)即可。

注意longlong。

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <stack>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #define ll long long
  14. #define inf 0x3f3f3f3f
  15. #define il inline
  16. namespace io {
  17. #define in(a) a = read()
  18. #define out(a) write(a)
  19. #define outn(a) out(a), putchar('\n')
  20. #define I_int ll
  21. inline I_int read() {
  22. I_int x = 0, f = 1;
  23. char c = getchar();
  24. while (c < '0' || c > '9') {
  25. if (c == '-') f = -1;
  26. c = getchar();
  27. }
  28. while (c >= '0' && c <= '9') {
  29. x = x * 10 + c - '0';
  30. c = getchar();
  31. }
  32. return x * f;
  33. }
  34. char F[200];
  35. inline void write(I_int x) {
  36. if (x == 0) return (void) (putchar('0'));
  37. I_int tmp = x > 0 ? x : -x;
  38. if (x < 0) putchar('-');
  39. int cnt = 0;
  40. while (tmp > 0) {
  41. F[cnt++] = tmp % 10 + '0';
  42. tmp /= 10;
  43. }
  44. while (cnt > 0) putchar(F[--cnt]);
  45. }
  46. #undef I_int
  47. }
  48. using namespace io;
  49. using namespace std;
  50. #define N 100010
  51. int n, m;
  52. int a[N], b[N], f[N];
  53. ll siz[N];
  54. ll ans = 0, sum = 0, res[N];
  55. int find(int x) {
  56. if(f[x] == x) return x;
  57. else return f[x] = find(f[x]);
  58. }
  59. int main() {
  60. in(n), in(m);
  61. sum = (ll)(n * (n - 1ll) / 2ll);
  62. for(int i = 1; i <= m; ++i) in(a[i]), in(b[i]);
  63. for(int i = 1; i <= n; ++i) f[i] = i, siz[i] = 1ll;
  64. for(int i = m; i; --i) {
  65. res[i] = sum - ans;
  66. int x = find(a[i]), y = find(b[i]);
  67. if(x != y) {
  68. ans += (ll)siz[x] * siz[y];
  69. siz[x] += siz[y];
  70. f[y] = x;
  71. }
  72. }
  73. for(int i = 1; i <= m; ++i) printf("%lld\n", res[i]);
  74. }

AtCoder Beginner Contest 120 解题报告的更多相关文章

  1. AtCoder Beginner Contest 122 解题报告

    手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...

  2. AtCoder Beginner Contest 146解题报告

    题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...

  3. Atcoder Beginner Contest 124 解题报告

    心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...

  4. AtCoder Beginner Contest 118 解题报告

    A - B +/- A #include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; b ...

  5. AtCoder Beginner Contest 117 解题报告

    果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...

  6. AtCoder Beginner Contest 132 解题报告

    前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...

  7. AtCoder Beginner Contest 129 解题报告

    传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...

  8. AtCoder Beginner Contest 127 解题报告

    传送门 非常遗憾.当天晚上错过这一场.不过感觉也会掉分的吧.后面两题偏结论题,打了的话应该想不出来. A - Ferris Wheel #include <bits/stdc++.h> u ...

  9. AtCoder Beginner Contest 126 解题报告

    突然6道题.有点慌.比赛写了五个.罚时爆炸.最后一个时间不太够+没敢写就放弃了. 两道题奇奇怪怪的WJ和20/20.今天的评测机是怎么了. A Changing a Character #includ ...

随机推荐

  1. BestCoder Round #55 ($)

    C 构造一个矩阵,然后采用矩阵快速幂 #include <iostream> #include <algorithm> #include <string.h> #i ...

  2. 排序(I)

    NSSortDescriptor 排序 Person类 #import <Foundation/Foundation.h> @interface Person : NSObject @pr ...

  3. IoC, DI,Spring.net

    IoC : Inversion of Control , 控制反转,就是创建对象(实例)的权利由开发人员自己控制New转到了由容器来控制.实现了解耦. DI: Dependency Injection ...

  4. js里用append()和appendChild有什么区别?

    parentNode.append()是还在试用期的方法,有兼容问题.是在parendNode节点中最后一个子节点后插入新Node或者DOMString(字符串,插入后为Text节点). 与paren ...

  5. javascript常用积累

    一.JS动画与动作不一致解决: if(!$( "#handle").is(":animated")){ //判断元素是否处于动画状态 } 二.停止事件冒泡 ev ...

  6. MySQL性能测试工具sysbench的安装和使用

    sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和PostgreSQL.当前 ...

  7. 自学Java第三个星期的总结

    在这一周里我在网上学习了java的分支结构.Number&Matht类.Character类.string类.String Buffer和String Builder类以及数组和日期时间等有关 ...

  8. TensorFlow 分布式实践

    此wiki主要介绍分布式环境使用的一些条件,一直所要注意的内容: 确保在此之前阅读过TensorFlow for distributed 1.集群描述 当前tensorflow 的版本(0.8.0), ...

  9. Django框架----logging配置

    我写Django项目常用的logging配置.(追加在setting.py文件中) LOGGING = { 'version': 1, 'disable_existing_loggers': Fals ...

  10. Centos搭建Seafile个人网盘

    1.安装依赖环境 yum install python python-setuptools python-imaging python-ldap python-memcached MySQL-pyth ...