大半年没有打Codeforces , 昨天开始恢复打Codeforces, 简直是, 欲语泪先流啊。

手残到爆的写错了范围, 手残的数漏了条件, 简直不能直视, 最坑爹的是, E题没时间写代码了。

题目链接

Problem_A:  

题意:

  给n个数, 每个数可以用无限次, 求用这些数的和表示不出来的最小的正整数, 没有则输出 -1.

思路:

  如果这n个数里面有1, 那么一定可以表示所有数, 没有1的话, 最小的正整数就是1

代码:

  

  1. 1 #include <cmath>
  2. 2 #include <cstdio>
  3. 3 #include <cstring>
  4. 4 #include <cstdlib>
  5. 5 #include <ctime>
  6. 6 #include <set>
  7. 7 #include <map>
  8. 8 #include <list>
  9. 9 #include <queue>
  10. 10 #include <string>
  11. 11 #include <vector>
  12. 12 #include <fstream>
  13. 13 #include <iterator>
  14. 14 #include <iostream>
  15. 15 #include <algorithm>
  16. 16 using namespace std;
  17. 17 #define LL long long
  18. 18 #define MAXN 1000010
  19. 19 #define MOD 1000000007
  20. 20 #define eps 1e-6
  21. 21 int n;
  22. 22
  23. 23 int main()
  24. 24 {
  25. 25 bool flag = false;
  26. 26 scanf("%d",&n);
  27. 27 for(int i = 0; i < n; i ++)
  28. 28 {
  29. 29 int x;
  30. 30 scanf("%d", &x);
  31. 31 if(x == 1) flag = true;
  32. 32 }
  33. 33 printf("%d\n",flag? -1 : 1);
  34. 34 return 0;
  35. 35 }
  36. 36

Problem_B:

题意:

  给三个矩形a, b, c。 问是否能将b和c放入a中。

思路:

  无非四种状态。

  1)都横着放。

  2)都竖着放。

  3)一横一竖。

    ①¬, 竖的放在横着的下面。

    ②|-,竖的放在横着的旁边。

  4)连接在一起。

    ①--, 横着连在一起。

    ②| , 竖着连在一起。

代码如下:

  

  1. 1 #include <cmath>
  2. 2 #include <cstdio>
  3. 3 #include <cstring>
  4. 4 #include <cstdlib>
  5. 5 #include <ctime>
  6. 6 #include <set>
  7. 7 #include <map>
  8. 8 #include <list>
  9. 9 #include <queue>
  10. 10 #include <string>
  11. 11 #include <vector>
  12. 12 #include <fstream>
  13. 13 #include <iterator>
  14. 14 #include <iostream>
  15. 15 #include <algorithm>
  16. 16 using namespace std;
  17. 17 #define LL long long
  18. 18 #define MAXN 4
  19. 19 #define MOD 1000000007
  20. 20 #define eps 1e-6
  21. 21 int a[MAXN], b[MAXN];
  22. 22 void show()
  23. 23 {
  24. 24 printf("fuck\n");
  25. 25 }
  26. 26 bool is_ok()
  27. 27 {
  28. 28 //1) =
  29. 29 if(max(a[1], a[2]) <= a[0] && (b[1] + b[2]) <= b[0]) return true;
  30. 30 //2)-- && |
  31. 31 if((a[1] + a[2] <= a[0]) && max(b[1], b[2]) <= b[0]) return true;
  32. 32 if((a[1] + a[2] <= b[0]) && max(b[1], b[2]) <= a[0]) return true;
  33. 33 //3)||
  34. 34 if((b[1] + b[2] ) <= a[0] && (max(a[1], a[2]) <= b[0])) return true;
  35. 35 //4)|-
  36. 36 if((b[1] + a[2] <= a[0]) && ((a[1] >= b[2]? a[1] : b[2]) <= b[0])) return true;
  37. 37 if((b[2] + a[1] <= a[0]) && ((a[2] >= b[1]? a[2] : b[1]) <= b[0])) return true;
  38. 38 //5)-|
  39. 39 if(((a[1] >= b[2]? a[1] : b[2]) <= a[0]) && (b[1] + a[2] <= b[0])) return true;
  40. 40 if(((a[2] >= b[1]? a[2] : b[1]) <= a[0]) && (b[2] + a[1] <= b[0])) return true;
  41. 41 return false;
  42. 42 }
  43. 43
  44. 44 int main()
  45. 45 {
  46. 46 for(int i = 0; i < 3; i ++)
  47. 47 scanf("%d %d",&a[i], &b[i]);
  48. 48 printf(is_ok()?"YES\n":"NO\n");
  49. 49 return 0;
  50. 50 }

Problem_C:

题意:

  给一个内角均为120°的六边形(不一定是正六边形), 问, 能将其分割成多少个单位三角形。

思路:

    

  将这个六边形的平行边延长, 相交于三点, 构成一个三角形, 可以证明这个三角形为等边三角形。

  因为六边形内角均为120°, 得到三个红色三角形的两个内角为60°, 所以得大三角形的三个顶角均为60°。

  所以, 等边三角形的边长为:(a1 + a2 + a3) = (a1 + a6 + a5) = (a1 + a2 + a6) = (a3 + a4 + a5) =....

  三角形每行有f(x)个单位三角形, x为每行底边长.

  f(x) = x + x - 1 = 2 * x - 1;

  f(1) = 1;

  f(x + 1) - f(x) = 2(x + 1) - 1 - (2 * x  - 1)

           = 2

  得, 解为:s(len) = f(1) + f(2) + ... + f(len), len 为等边三角形边长。

           =(1 + 2 * x - 1) * x / 2

           =x ^ 2

  所以, 边长为n 的等边三角形所含单位三角形数为 s(n)。

  题目所有的六边形所含单位三角形数为:s(n) - f(a1) - f(a3) - f(a5)。

  即, 减去三个角的等边三角形, 剩下的就是六边形所包含的

代码如下:

  

  1. 1 #include <cmath>
  2. 2 #include <cstdio>
  3. 3 #include <cstring>
  4. 4 #include <cstdlib>
  5. 5 #include <ctime>
  6. 6 #include <set>
  7. 7 #include <map>
  8. 8 #include <list>
  9. 9 #include <queue>
  10. 10 #include <string>
  11. 11 #include <vector>
  12. 12 #include <fstream>
  13. 13 #include <iterator>
  14. 14 #include <iostream>
  15. 15 #include <algorithm>
  16. 16 using namespace std;
  17. 17 #define LL long long
  18. 18 #define MAXN 7
  19. 19 #define MAXM 4000
  20. 20 #define MOD 1000000007
  21. 21 #define eps 1e-6
  22. 22 int a[MAXN];
  23. 23 int fac[MAXM];
  24. 24 void init()
  25. 25 {
  26. 26 fac[0] = 1;
  27. 27 for(int i = 1; i < MAXM; i++)
  28. 28 fac[i] = i * i;
  29. 29 }
  30. 30
  31. 31 int main()
  32. 32 {
  33. 33 init();
  34. 34 for(int i = 1; i <= 6; i ++)
  35. 35 scanf("%d",&a[i]);
  36. 36 int ans = fac[a[1] + a[2] + a[3]] - fac[a[1]] - fac[a[3]] - fac[a[5]];
  37. 37 printf("%d\n",ans);
  38. 38 return 0;
  39. 39 }

Problem_D:

题意:

  给两个字符串a,b, 判断它们是否等价。

  等价的定义:

  满足下列条件之一的就是等价。

  1)a == b

  2)将字符串a, 分成两部分长度相等的子串a1, a2, b 分成两部分长度相等的子串b1, b2, 满足下列条件之一

    ①a1 == b1 并且 a2 == b2

    ②a1 == b2 并且 a2 == b1

思路:

  暴力模拟查找, 也可以hash之后再找, 降低查找的复杂度为O(1)。

  队友写了一发hash, 我直接暴力的。

  暴力模拟注意string , cin 会超时, 需要用char[] , scanf()。

代码如下:

  

  1. 1 #include <cmath>
  2. 2 #include <cstdio>
  3. 3 #include <cstring>
  4. 4 #include <cstdlib>
  5. 5 #include <ctime>
  6. 6 #include <set>
  7. 7 #include <map>
  8. 8 #include <list>
  9. 9 #include <queue>
  10. 10 #include <string>
  11. 11 #include <vector>
  12. 12 #include <fstream>
  13. 13 #include <iterator>
  14. 14 #include <iostream>
  15. 15 #include <algorithm>
  16. 16 using namespace std;
  17. 17 #define LL long long
  18. 18 #define MAXN 2000010
  19. 19 #define MOD 1000000007
  20. 20 #define eps 1e-6
  21. 21 char str_a[MAXN], str_b[MAXN];
  22. 22 bool dfs(int pos_a, int pos_b, int len)
  23. 23 {
  24. 24 if(!strncmp(str_a + pos_a, str_b + pos_b, len)) return true;
  25. 25 if(len & 1) return false;
  26. 26 int sub_len = len / 2;
  27. 27 return (dfs(pos_a , pos_b, sub_len) && dfs(pos_a + sub_len, pos_b + sub_len, sub_len))
  28. 28 || (dfs(pos_a + sub_len, pos_b , sub_len) && dfs(pos_a , pos_b + sub_len, sub_len));
  29. 29 }
  30. 30
  31. 31 int main()
  32. 32 {
  33. 33 scanf("%s %s", str_a, str_b);
  34. 34 printf(dfs(0, 0, strlen(str_a)) ? "YES\n" : "NO\n");
  35. 35 return 0;
  36. 36 }

Problem_E:

题意:

  给一个h*w的棋盘, 只能往右走, 往下走, 有n个黑格子, 黑格子不能走,问从左上角走到右下角有多少种方案数。

思路:

  组合数学书上的一个例题,原题只是背景不同。

  这里利用减法原理, 求出所有经过黑格子的方案数, 再用总的方案数减去就得到答案。

  sum = C(h - 1 + w - 1, h - 1)

  设dp[i] 为从左上角不经过任何黑格子走到第i个黑格子的方案数,

  dp[i] = C(x[i] - 1 + y[i] - 1, x[i] - 1) - sigma(x[j] <= x[i] && y[j] <= y[i]) dp[j] * C(x[i] - x[j] + y[i] - y[j], x[i] - x[j])

  红色部分为(1,1)到(x[i],y[[i])这个矩形区域内, 经过黑格子到(i,j)的方案数。

  则经过第i个黑格子到达右下角的方案数为:dp[i] * C(h - x[i] + w - y[i], w - [i])。

  再用sum 减去所有的dp[i]即可。

代码如下:

  

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <set>
  7. #include <map>
  8. #include <list>
  9. #include <queue>
  10. #include <string>
  11. #include <vector>
  12. #include <fstream>
  13. #include <iterator>
  14. #include <iostream>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. #define MAXN 2020
  19. #define MAXM 500010
  20. #define MOD 1000000007
  21. #define eps 1e-6
  22. int w, h, n;
  23. LL dp[MAXN];
  24. LL fac[MAXM], fack[MAXM];
  25. struct node
  26. {
  27. int x;
  28. int y;
  29. };
  30. struct node f[MAXN];
  31. bool cmp(struct node x, struct node y)
  32. {
  33. if(x.x == y.x) return x.y < y.y;
  34. return x.x < y.x;
  35. }
  36. LL qpow(LL x, LL k)
  37. {
  38. LL res = ;
  39. while(k)
  40. {
  41. if(k & ) res = res * x % MOD;
  42. x = x * x % MOD;
  43. k >>= ;
  44. }
  45. return res;
  46. }
  47. LL C(LL n, LL m)
  48. {
  49. if(m < || m > n) return ;
  50. return fac[n] * fack[m] % MOD * fack[n-m] % MOD;
  51. }
  52. void init()
  53. {
  54. fac[] = fack[] = fac[] = fack[] = ;
  55. for(int i = ; i < MAXM; i ++)
  56. {
  57. fac[i] = fac[i-] * i % MOD;
  58. fack[i] = qpow(fac[i], MOD - );
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. init();
  65. scanf("%d %d %d", &h, &w, &n);
  66. for(int i = ; i < n; i ++)
  67. scanf("%d %d",&f[i].x, &f[i].y);
  68. memset(dp, , sizeof(dp));
  69. sort(f, f + n, cmp);
  70. //ans = C(h + w - 2, h - 1)
  71. //dp[i] = C(f[i].x + f[i].y - 2, f[i].x - 1) - dp[j] * C(f[i].x - f[j].x + f[i].y - f[j].y, f[i].x - f[j].x)
  72. //ans -= dp[i] * C(h - f[i].x + w - f[i].y, h -f[i].x)
  73. LL ans = C(h + w - , h - );
  74. for(int i = ; i < n; i ++)
  75. {
  76. dp[i] = C(f[i].x + f[i].y - , f[i].x - );
  77. for(int j = ; j < i; j ++)
  78. if(f[j].x <= f[i].x && f[j].y <= f[i].y)
  79. {
  80. dp[i] -= (dp[j] * C(f[i].x - f[j].x + f[i].y - f[j].y, f[i].x - f[j].x));
  81. dp[i] = (dp[i] + MOD) % MOD;
  82. }
  83. ans = ((ans - (dp[i] * C(h - f[i].x + w - f[i].y, h - f[i].x))) % MOD + MOD) % MOD;
  84. }
  85. printf("%I64d\n", ans);
  86. return ;
  87. }

Codeforces Round #313 (Div. 2)的更多相关文章

  1. Codeforces Round #313 (Div. 1)

    官方英文题解:http://codeforces.com/blog/entry/19237 Problem A: 题目大意: 给出内角和均为120°的六边形的六条边长(均为正整数),求最多能划分成多少 ...

  2. dp - Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess

    Gerald and Giant Chess Problem's Link: http://codeforces.com/contest/559/problem/C Mean: 一个n*m的网格,让你 ...

  3. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  4. Codeforces Round #313 (Div. 1) A. Gerald's Hexagon

    Gerald's Hexagon Problem's Link: http://codeforces.com/contest/559/problem/A Mean: 按顺时针顺序给出一个六边形的各边长 ...

  5. Codeforces Round #313 (Div. 2)B.B. Gerald is into Art

    B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/ ...

  6. Codeforces Round #313 (Div. 2) D. Equivalent Strings

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

  7. Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学

    C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...

  8. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

    A. Currency System in Geraldion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  9. Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)

    题目链接:http://codeforces.com/contest/560/problem/E 给你一个n*m的网格,有k个坏点,问你从(1,1)到(n,m)不经过坏点有多少条路径. 先把这些坏点排 ...

  10. Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力

    B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...

随机推荐

  1. Python数据类型转换

    Python数据类型之间的转换 函数 描述 int(x [,base]) 将x转换为一个整数 long(x [,base] ) 将x转换为一个长整数 float(x) 将x转换到一个浮点数 compl ...

  2. HTTP 404 - 未找到文件 怎么样解决

    找不到网页  您要查看的网页可能已被删除.名称已被更改,或者临时不可用.  -------------------------------------------------------------- ...

  3. mybatis03

    .2导入jar包 从mybatis管网下载(地址:https://github.com/mybatis/mybatis-3/releases) mybatis-.pdf---操作手册 mybatis- ...

  4. 关于XCode5打开工程闪退的一种解决方案

    今天同事遇到一个问题,是关于xcode5打开工程文件一直闪退的问题.后来查看了一下崩溃日志.有如下描述: xception Type: EXC_CRASH (SIGABRT) Exception Co ...

  5. java注释 命名 数据类型 基本类型转换 位运算符 逻辑运算符 三目运算符

    一.java注释 1.单行注释  //注释内容 2.多行注释 /*注释内容*/ 3.文档注释(可用javadoc工具生成api文档,不过我还没试过)/**文档注释*/,文档注释可以在使用的时候看见注释 ...

  6. 如何创建一个自己的【Composer/Packagist】包

    首先让我们踏着欢快的脚步去Github创建一个新库,这里取名 composer-car,又欢快的将它克隆到本地: $ git clone git@github.com:victorruan/compo ...

  7. final----这篇文章是我收获很大

    final 用于声明属性.方法和类,分别表示属性不可变,方法不可重写,类不可继承. [转]Java final 修饰符知识点总结 final从字面上理解含义为“最后的,最终的”.在Java中也同样表示 ...

  8. chrome偶尔弹出新窗口的解决方案

    最近使用谷歌浏览器,在搜索页点击搜索结果时,偶尔会弹出新窗口,而不是新标签,试验发现,只要将chrome里面安装的google drive app卸载就行了. 当然了,如果此方法不适合你的情况,还可以 ...

  9. Mono For Android的项目发布

    Mono for Android的发布步骤: 1.选择项目名称鼠标右键,选择Options选项. 2.弹出工程选项框,选择Android Build,勾选 Supported ABIS里面的所有项. ...

  10. jmeter压测SSL加密网站

    1.生成秘钥文件 得到网站证书,用jdk自带的keytool生成秘钥文件,执行dos命令: keytool     -import -alias "aaa" -file " ...