M-SOLUTIONS Programming Contest

A - Sum of Interior Angles

  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 eps 1e-10
  10. #define MAXN 200005
  11. #define ba 47
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef unsigned int u32;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;T f = 1;char c = getchar();
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 +c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int N;
  39. void Solve() {
  40. read(N);
  41. out((N - 2) * 180);enter;
  42. }
  43. int main() {
  44. #ifdef ivorysi
  45. freopen("f1.in","r",stdin);
  46. #endif
  47. Solve();
  48. return 0;
  49. }

B - Sumo

  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 eps 1e-10
  10. #define MAXN 200005
  11. #define ba 47
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef unsigned int u32;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;T f = 1;char c = getchar();
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 +c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int L;
  39. char s[20];
  40. void Solve() {
  41. scanf("%s",s + 1);
  42. L = strlen(s + 1);
  43. int ans = 15 - L;
  44. for(int i = 1 ; i <= L ; ++i) {
  45. if(s[i] == 'o') ++ans;
  46. }
  47. if(ans >= 8) puts("YES");
  48. else puts("NO");
  49. }
  50. int main() {
  51. #ifdef ivorysi
  52. freopen("f1.in","r",stdin);
  53. #endif
  54. Solve();
  55. return 0;
  56. }

C - Best-of-(2n-1)

就是有\(C\)的概率往下摁,否则就停止,这样的期望次数是\(\frac{C}{1 - C}\)

我们枚举最终情况走了\(i\)个\(A\)和\(N\)个\(B\)(反过来同理),这个时候\(A\)胜的概率是\(\frac{A}{A+ B}\),\(B\)胜的概率是\(\frac{B}{A+ B}\),期望次数就是\((N + i)(\frac{C}{1 - C} + 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 eps 1e-10
  10. #define MAXN 100005
  11. #define ba 47
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef unsigned int u32;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;T f = 1;char c = getchar();
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 +c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. const int MOD = 1000000007;
  39. int fac[1000005],invfac[1000005];
  40. int N,A,B,C;
  41. int inc(int a,int b) {
  42. return a + b >= MOD ? a + b - MOD : a + b;
  43. }
  44. int mul(int a,int b) {
  45. return 1LL * a * b % MOD;
  46. }
  47. void update(int &a,int b) {
  48. a = inc(a,b);
  49. }
  50. int cnm(int n,int m) {
  51. if(n < m) return 0;
  52. else return mul(fac[n],mul(invfac[m],invfac[n - m]));
  53. }
  54. int fpow(int x,int c) {
  55. int res = 1,t = x;
  56. while(c) {
  57. if(c & 1) res = mul(res,t);
  58. t = mul(t,t);
  59. c >>= 1;
  60. }
  61. return res;
  62. }
  63. void Solve() {
  64. read(N);read(A);read(B);read(C);
  65. A = mul(A,fpow(100,MOD - 2));
  66. B = mul(B,fpow(100,MOD - 2));
  67. C = mul(C,fpow(100,MOD - 2));
  68. int iv = fpow(inc(1,MOD - C),MOD - 2);
  69. C = mul(C,iv);
  70. int k = fpow(inc(A,B),MOD - 2);
  71. A = mul(A,k);B = mul(B,k);
  72. fac[0] = 1;
  73. for(int i = 1 ; i <= 2 * N ; ++i) {
  74. fac[i] = mul(fac[i - 1],i);
  75. }
  76. invfac[2 * N] = fpow(fac[2 * N],MOD - 2);
  77. for(int i = 2 * N - 1 ; i >= 0 ; --i) {
  78. invfac[i] = mul(invfac[i + 1],i + 1);
  79. }
  80. int ans = 0;
  81. for(int i = 0 ; i < N ; ++i) {
  82. int h = inc(mul(fpow(A,N),fpow(B,i)),mul(fpow(B,N),fpow(A,i)));
  83. int t = mul(cnm(i + N - 1,N - 1),mul(C + 1,i + N));
  84. t = mul(t,h);
  85. update(ans,t);
  86. }
  87. out(ans);enter;
  88. }
  89. int main() {
  90. #ifdef ivorysi
  91. freopen("f1.in","r",stdin);
  92. #endif
  93. Solve();
  94. return 0;
  95. }

D - Maximum Sum of Minimum

大胆猜想一下发现就是除了最大值都加一遍,如果一个值加了两遍会占一个比它大的值得位置,不优,构造的话就是随便选一个根然后按dfs序从大到小填数

  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 eps 1e-10
  10. #define MAXN 10005
  11. #define ba 47
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef unsigned int u32;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;T f = 1;char c = getchar();
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 +c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. struct node {
  39. int to,next;
  40. }E[MAXN * 2];
  41. int sumE,head[MAXN],N;
  42. int c[MAXN],ans;
  43. int p[MAXN],tot;
  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. p[u] = c[tot--];
  51. for(int i = head[u] ; i ; i = E[i].next) {
  52. int v = E[i].to;
  53. if(v != fa) {
  54. dfs(v,u);
  55. }
  56. }
  57. }
  58. void Solve() {
  59. read(N);
  60. int a,b;
  61. for(int i = 1 ; i < N ; ++i) {
  62. read(a);read(b);add(a,b);add(b,a);
  63. }
  64. for(int i = 1 ; i <= N ; ++i) read(c[i]);
  65. sort(c + 1,c + N + 1);
  66. for(int i = 1 ; i < N ; ++i) ans += c[i];
  67. tot = N;
  68. dfs(1,0);
  69. out(ans);enter;
  70. for(int i = 1 ; i <= N ; ++i) {
  71. out(p[i]);space;
  72. }
  73. enter;
  74. }
  75. int main() {
  76. #ifdef ivorysi
  77. freopen("f1.in","r",stdin);
  78. #endif
  79. Solve();
  80. return 0;
  81. }

E - Product of Arithmetic Progression

没做出来的我真是降智

如果d=0,那么答案是\(x^{n}\)

如果d不为0,都除上一个d,然后发现是一段连续的数相乘,可以用前缀乘积的一个除另一个,特判掉\(x = 0\)和\(\frac{x}{d} + n - 1 >= P\)的情况,最后再乘上\(d^{n}\)

  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 eps 1e-10
  10. #define MAXN 10005
  11. #define ba 47
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef unsigned int u32;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;T f = 1;char c = getchar();
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 +c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. const int MOD = 1000003;
  39. int pre[MOD + 5];
  40. int mul(int a,int b) {
  41. return 1LL * a * b % MOD;
  42. }
  43. int inc(int a,int b) {
  44. return a + b >= MOD ? a + b - MOD : a + b;
  45. }
  46. int fpow(int x,int c) {
  47. int res = 1,t = x;
  48. while(c) {
  49. if(c & 1) res = mul(res,t);
  50. t = mul(t,t);
  51. c >>= 1;
  52. }
  53. return res;
  54. }
  55. void Solve() {
  56. pre[0] = 1;
  57. for(int i = 1 ; i < MOD ; ++i) pre[i] = mul(pre[i - 1],i);
  58. int Q,x,d,n;
  59. read(Q);
  60. for(int i = 1 ; i <= Q ; ++i) {
  61. read(x);read(d);read(n);
  62. if(d == 0) {out(fpow(x,n));enter;continue;}
  63. x = mul(x,fpow(d,MOD - 2));
  64. if(x + n - 1 >= MOD || x == 0) {puts("0");continue;}
  65. int res = mul(pre[x + n - 1],fpow(pre[x - 1],MOD - 2));
  66. res = mul(res,fpow(d,n));
  67. out(res);enter;
  68. }
  69. }
  70. int main() {
  71. #ifdef ivorysi
  72. freopen("f1.in","r",stdin);
  73. #endif
  74. Solve();
  75. return 0;
  76. }

F - Random Tournament

设\(dpl[i][j]\)表示这个区间\([i,j]\)有一种方式是\(i\)能打败所有人

\(dpr[i][j]\)表示有一种方式\(j\)能打败所有人

答案就是\(dpr[1][x] = 1\)并且\(dpl[x][N] = 1\)的所有位置

然后\(dpr[l][r]\)为1的条件是存在\(k\)使得\(dpr[l][k] = 1\)并且\(dpl[k][r - 1] = 1\)并且\(a_{r,k} = 1\)

\(dpl[l][r]\)是存在\(k\)使得\(dpr[l + 1][k] = 1\)并且\(dpl[k][r] = 1\)并且\(a_{l,k} = 1\)

这个可以用bitset优化,所以复杂度是\(O(\frac{N^{3}}{w})\)

  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 eps 1e-10
  10. #define MAXN 10005
  11. #define ba 47
  12. //#define ivorysi
  13. using namespace std;
  14. typedef long long int64;
  15. typedef unsigned int u32;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;T f = 1;char c = getchar();
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 +c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. bitset<2005> a[2005],dpr[2005],dpl[2005],tmp;
  39. int N;
  40. char s[2005][2005];
  41. void Solve() {
  42. read(N);
  43. for(int i = 2 ; i <= N ; ++i) {
  44. scanf("%s",s[i] + 1);
  45. for(int j = 1 ; j < i ; ++j) {
  46. if(s[i][j] == '1') a[i][j] = 1;
  47. else a[j][i] = 1;
  48. }
  49. }
  50. for(int i = 1 ; i <= N ; ++i) dpr[i][i] = 1,dpl[i][i] = 1;
  51. for(int d = 2 ; d <= N ; ++d) {
  52. for(int l = 1 ; l <= N ; ++l) {
  53. int r = l + d - 1;
  54. if(r > N) break;
  55. if((dpr[l] & dpl[r - 1] & a[r]).any()) {
  56. dpr[l][r] = 1;
  57. }
  58. if((dpl[r] & dpr[l + 1] & a[l]).any()) {
  59. dpl[r][l] = 1;
  60. }
  61. }
  62. }
  63. out((dpr[1] & dpl[N]).count());enter;
  64. }
  65. int main() {
  66. #ifdef ivorysi
  67. freopen("f1.in","r",stdin);
  68. #endif
  69. Solve();
  70. return 0;
  71. }

【AtCoder】M-SOLUTIONS Programming Contest的更多相关文章

  1. 【AtCoder】diverta 2019 Programming Contest 2

    diverta 2019 Programming Contest 2 A - Ball Distribution 特判一下一个人的,否则是\(N - (K - 1) - 1\) #include &l ...

  2. 【AtCoder】diverta 2019 Programming Contest

    diverta 2019 Programming Contest 因为评测机的缘故--它unrated了.. A - Consecutive Integers #include <bits/st ...

  3. 【题解】CF1056F Write the Contest(三分+贪心+DP)

    [题解]CF1056F Write the Contest(三分+贪心+DP) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...

  4. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  5. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  6. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  7. 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers

    https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...

  8. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  9. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

随机推荐

  1. 添加tag

    创建tag git tag -a V1 -m 'release 1' 创建了本地一个版本v1,同时添加注释 release 1 查看tag git tag 显示注释 git show V1 本地tag ...

  2. php使用ZipArchive提示Fatal error: Class ZipArchive not found in的解决方法

    使用压缩包函数必须要安装zip扩展,否则会报错 $ apt install php-zip

  3. Python互联网金融之用户增长的数据逻辑

    怎样看待和应用我们互联网金融中的数据? 怎样进行数据分析? 互联网金融数据分析的三个层面: (1)指标层面 建立指标体系,观察指标涨跌的情况 (2)行业框架 不同的行业对于各个指标的权重不同 复投率 ...

  4. try catch块的秘密

    最近有同事遇到问题: 她在4处手动抛运行异常,5处存在return语句,结果程序在2出现异常时没有抛出运行异常,导致事务不一致. 我们都知道,当程序出现异常时候并且在不采取任何措施的情况下,是会抛出异 ...

  5. slax linux的定制

    由于数据结构教学的需要,需要用到linux,要求就是小,启动快,可定制性强,恰好slax正好满足要求,以下就是定制slax linux的过程记录: 什么是Slax Slax是一个基于Linux的Liv ...

  6. Wondershare Video Converter Ultimate 注册码 License

    这个软件可以直接将DVD iso转换成mp4播放,可以破解,还不错,特地记录 官网下载最新版: https://videoconverter.wondershare.com/gl/video-conv ...

  7. puppeteer学习笔记合集

    官方英文版API入口(如果你英文好的话):https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md. 汉化版API入口(网上有 ...

  8. AddLayer和AddTag

    using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; pu ...

  9. /proc/sys/kernel/sysrq /proc/sysrq-trigger----强制重启/触发器

    LINUX远程强制重启/proc/sys/kernel/sysrq /proc/sysrq-trigger----触发器 ttp://blog.csdn.net/beckdon/article/det ...

  10. mac 设置 MySQL 数据库默认编码(字符集)为 UTF-8

    mac 设置 MySQL 数据库默认编码(字符集)为 UTF-8   原文链接:https://juejin.im/post/5bbdca76e51d45021147de44 鉴于有些刚接触 MySQ ...