A题,n*m根木棍,相交放置,轮流取走相交的两根,最后谁不能行动,则输掉。

min(n,m)&1 为1则先取者赢。

B题,给定一个长度为n,且各不相同的数组,问能否通过交换连续一段L....R使得变成单调递增。

如果一开始就是递增的,那么直接输出L。。。R就是1 1,交换一个就行了;否则判断中间是否有且一段单调递减,且两端交换后使得数组递增。

代码:

  1. //Template updates date: 20140718
  2. #include <iostream>
  3. #include <sstream>
  4. #include <cstdio>
  5. #include <climits>
  6. #include <ctime>
  7. #include <cctype>
  8. #include <cstring>
  9. #include <cstdlib>
  10. #include <string>
  11. #include <stack>
  12. #include <set>
  13. #include <map>
  14. #include <cmath>
  15. #include <vector>
  16. #include <queue>
  17. #include <algorithm>
  18. #define esp 1e-6
  19. #define inf 0x3f3f3f3f
  20. #define pi acos(-1.0)
  21. #define pb push_back
  22. #define lson l, m, rt<<1
  23. #define rson m+1, r, rt<<1|1
  24. #define lowbit(x) (x&(-x))
  25. #define mp(a, b) make_pair((a), (b))
  26. #define bit(k) (1<<(k))
  27. #define iin freopen("pow.in", "r", stdin);
  28. #define oout freopen("pow.out", "w", stdout);
  29. #define in freopen("solve_in.txt", "r", stdin);
  30. #define out freopen("solve_out.txt", "w", stdout);
  31. #define bug puts("********))))))");
  32. #define Inout iin oout
  33. #define inout in out
  34.  
  35. #define SET(a, v) memset(a, (v), sizeof(a))
  36. #define SORT(a) sort((a).begin(), (a).end())
  37. #define REV(a) reverse((a).begin(), (a).end())
  38. #define READ(a, n) {REP(i, n) cin>>(a)[i];}
  39. #define REP(i, n) for(int i = 0; i < (n); i++)
  40. #define VREP(i, n, base) for(int i = (n); i >= (base); i--)
  41. #define Rep(i, base, n) for(int i = (base); i < (n); i++)
  42. #define REPS(s, i) for(int i = 0; (s)[i]; i++)
  43. #define pf(x) ((x)*(x))
  44. #define mod(n) ((n))
  45. #define Log(a, b) (log((double)b)/log((double)a))
  46. #define Srand() srand((int)time(0))
  47. #define random(number) (rand()%number)
  48. #define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a)
  49.  
  50. using namespace std;
  51. typedef long long LL;
  52. typedef unsigned long long ULL;
  53. typedef vector<int> VI;
  54. typedef pair<int,int> PII;
  55. typedef vector<PII> VII;
  56. typedef vector<PII, int> VIII;
  57. typedef VI:: iterator IT;
  58. typedef map<string, int> Mps;
  59. typedef map<int, int> Mpi;
  60. typedef map<int, PII> Mpii;
  61. typedef map<PII, int> Mpiii;
  62.  
  63. const int maxn = + ;
  64. int a[maxn];
  65.  
  66. int main() {
  67.  
  68. int n;
  69. Rep(i, scanf("%d", &n), n+) scanf("%d", a+i);
  70. int l = , r = ;
  71. int ok = ;
  72. a[n+] = inf;
  73. Rep(i, , n+) {
  74. if(a[i] > a[i-]) {
  75. if(!l)
  76. continue;
  77. else {
  78. if(ok && !r)
  79. r = i-;
  80. }
  81. } else if(a[i] < a[i-]) {
  82. if(!ok)
  83. ok = , l = i-;
  84. if(r) {
  85. cout<<"no"<<endl;
  86. return ;
  87. }
  88. } else {
  89. cout<<"no"<<endl;
  90. return ;
  91. }
  92. }
  93. if(l) {
  94. if(a[l] < a[r+] && a[r] > a[l-]) {
  95. cout<<"yes"<<endl;
  96. cout<<l <<' '<<r<<endl;
  97. } else {
  98. cout<<"no"<<endl;
  99. }
  100. } else {
  101. cout<<"yes"<<endl;
  102. cout<<<<' '<<<<endl;
  103. }
  104. return ;
  105. }

写得挫。

C题,3个球队,总共n场比赛,已进行k场,知道两个球队之间赢得场数的绝对值,如|x1-x2| = d1, |x2-x3| = d2, 问剩下的比赛中是否存在一种可能使得三个队伍赢得场数相等。

分析:题意知道每场比赛只用知道谁赢就行 ,不用顾忌各种规则,前k场中分别可能情况:

令x = x2;

x+d1, x, x+d2;

x+d1, x, x-d2;

x-d1, x, x+d2;

x-d1, x, x-d1;

对应4种情况求出x,在求出x1,x2,x3,判断满足0<=xi<=n/3 && xi <= k;

就可以了。

代码:

  1. //Template updates date: 20140718
  2. #include <iostream>
  3. #include <sstream>
  4. #include <cstdio>
  5. #include <climits>
  6. #include <ctime>
  7. #include <cctype>
  8. #include <cstring>
  9. #include <cstdlib>
  10. #include <string>
  11. #include <stack>
  12. #include <set>
  13. #include <map>
  14. #include <cmath>
  15. #include <vector>
  16. #include <queue>
  17. #include <algorithm>
  18. #define esp 1e-6
  19. #define inf 0x3f3f3f3f
  20. #define pi acos(-1.0)
  21. #define pb push_back
  22. #define lson l, m, rt<<1
  23. #define rson m+1, r, rt<<1|1
  24. #define lowbit(x) (x&(-x))
  25. #define mp(a, b) make_pair((a), (b))
  26. #define bit(k) (1<<(k))
  27. #define iin freopen("pow.in", "r", stdin);
  28. #define oout freopen("pow.out", "w", stdout);
  29. #define in freopen("solve_in.txt", "r", stdin);
  30. #define out freopen("solve_out.txt", "w", stdout);
  31. #define bug puts("********))))))");
  32. #define Inout iin oout
  33. #define inout in out
  34.  
  35. #define SET(a, v) memset(a, (v), sizeof(a))
  36. #define SORT(a) sort((a).begin(), (a).end())
  37. #define REV(a) reverse((a).begin(), (a).end())
  38. #define READ(a, n) {REP(i, n) cin>>(a)[i];}
  39. #define REP(i, n) for(int i = 0; i < (n); i++)
  40. #define VREP(i, n, base) for(int i = (n); i >= (base); i--)
  41. #define Rep(i, base, n) for(int i = (base); i < (n); i++)
  42. #define REPS(s, i) for(int i = 0; (s)[i]; i++)
  43. #define pf(x) ((x)*(x))
  44. #define mod(n) ((n))
  45. #define Log(a, b) (log((double)b)/log((double)a))
  46. #define Srand() srand((int)time(0))
  47. #define random(number) (rand()%number)
  48. #define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a)
  49.  
  50. using namespace std;
  51. typedef long long LL;
  52. typedef unsigned long long ULL;
  53. typedef vector<int> VI;
  54. typedef pair<int,int> PII;
  55. typedef vector<PII> VII;
  56. typedef vector<PII, int> VIII;
  57. typedef VI:: iterator IT;
  58. typedef map<string, int> Mps;
  59. typedef map<int, int> Mpi;
  60. typedef map<int, PII> Mpii;
  61. typedef map<PII, int> Mpiii;
  62.  
  63. LL n, k, d1, d2;
  64. int a[][] = {{-, } ,{-, -}, {, }, {, -}};
  65.  
  66. int main() {
  67. int T;
  68. for(int t = scanf("%d", &T); t <= T; t++) {
  69. scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2);
  70. if(n%) {
  71. puts("no");
  72. continue;
  73. }
  74. int ok = ;
  75. LL nn;
  76. REP(i, ) {
  77. nn = k;
  78. LL tmp = (LL)a[i][]*d1+(LL)a[i][]*d2;
  79. nn -= tmp;
  80. if(nn < || nn%)
  81. continue;
  82. nn /= ;
  83. if(nn > n/ || nn > k)
  84. continue;
  85. LL x1 = nn+(LL)a[i][]*d1;
  86. LL x2 = nn+(LL)a[i][]*d2;
  87. if(x1 < || x1 > n/ || x2 < || x2 > n/ || x1 > k || x2 > k)
  88. continue;
  89. ok = ;
  90. break;
  91. }
  92. puts(ok ? "yes" : "no");
  93. }
  94. return ;
  95. }

D题,给定仅有‘a','a'组成的字符串,定义一种子串:通过合并连续的字母最后可以得到一个回文串。如”aaabbaaa"最后得到"aba"。

很容易想到一个字串首尾字符相等时就为这样的要求的特殊字串。

题目要求奇数长度和偶数长度这样的字串个数,统计每个字符分别用dp[0][s[i]-'a'], dp[1][s[i]-'a'],表示位于i及之前的奇数位置和偶数位置的s[i]字符个数,

这样偶数长度ans0 += dp[!(i&1)][s[i]-'a'], 奇数长度ans1 += dp[i&1][s[i]-'a'];

代码:

  1. //Template updates date: 20140718
  2. #include <iostream>
  3. #include <sstream>
  4. #include <cstdio>
  5. #include <climits>
  6. #include <ctime>
  7. #include <cctype>
  8. #include <cstring>
  9. #include <cstdlib>
  10. #include <string>
  11. #include <stack>
  12. #include <set>
  13. #include <map>
  14. #include <cmath>
  15. #include <vector>
  16. #include <queue>
  17. #include <algorithm>
  18. #define esp 1e-6
  19. #define inf 0x3f3f3f3f
  20. #define pi acos(-1.0)
  21. #define pb push_back
  22. #define lson l, m, rt<<1
  23. #define rson m+1, r, rt<<1|1
  24. #define lowbit(x) (x&(-x))
  25. #define mp(a, b) make_pair((a), (b))
  26. #define bit(k) (1<<(k))
  27. #define iin freopen("pow.in", "r", stdin);
  28. #define oout freopen("pow.out", "w", stdout);
  29. #define in freopen("solve_in.txt", "r", stdin);
  30. #define out freopen("solve_out.txt", "w", stdout);
  31. #define bug puts("********))))))");
  32. #define Inout iin oout
  33. #define inout in out
  34.  
  35. #define SET(a, v) memset(a, (v), sizeof(a))
  36. #define SORT(a) sort((a).begin(), (a).end())
  37. #define REV(a) reverse((a).begin(), (a).end())
  38. #define READ(a, n) {REP(i, n) cin>>(a)[i];}
  39. #define REP(i, n) for(int i = 0; i < (n); i++)
  40. #define VREP(i, n, base) for(int i = (n); i >= (base); i--)
  41. #define Rep(i, base, n) for(int i = (base); i < (n); i++)
  42. #define REPS(s, i) for(int i = 0; (s)[i]; i++)
  43. #define pf(x) ((x)*(x))
  44. #define mod(n) ((n))
  45. #define Log(a, b) (log((double)b)/log((double)a))
  46. #define Srand() srand((int)time(0))
  47. #define random(number) (rand()%number)
  48. #define random_range(a, b) (int)(((double)rand()/RAND_MAX)*(b-a) + a)
  49.  
  50. using namespace std;
  51. typedef long long LL;
  52. typedef unsigned long long ULL;
  53. typedef vector<int> VI;
  54. typedef pair<int,int> PII;
  55. typedef vector<PII> VII;
  56. typedef vector<PII, int> VIII;
  57. typedef VI:: iterator IT;
  58. typedef map<string, int> Mps;
  59. typedef map<int, int> Mpi;
  60. typedef map<int, PII> Mpii;
  61. typedef map<PII, int> Mpiii;
  62.  
  63. const int maxn = + ;
  64. char s[maxn];
  65. LL dp[][];
  66. int main() {
  67.  
  68. scanf("%s", s);
  69. LL ans1 = , ans2 = ;
  70. REPS(s, i) {
  71. int x = s[i]-'a';
  72. int y = i&;
  73. dp[y][x]++;
  74. ans1+=dp[y][x];
  75. ans2+=dp[y^][x];
  76. }
  77. cout<<ans2<<' '<<ans1<<endl;
  78. return ;
  79. }

E题,n个箱子装有fi朵花,箱子内花完全一样,箱子之间花看做不同,求从中选出s朵花,有多少选法?

我也不会数论,不过还是硬着头皮看懂了。以后要慢慢积累啊

分析: 设第i个箱子选出xi朵花。得到x1+x2+x3.....xn = s, 且0<=xi<=fi.

那么选花方案数就是解的组数,即(1+x+x^2+x^3+.....x^f1)*................(1+x+x^2+x^3+x^4.........x^fn)

= (1-x^(f1+1))******(1-x^(fn+1)) *(1-x)^(-n)(等比数列)中x^s系数

然后就是求里面x^s的系数了。

这个先算出前面部分各次幂的系数诚意后面(1-x)^(-n)相应系数,使得总系数为s。

其中(1-x)^(-n)幂为k的系数为C(n+k-1, k) = C(n+k-1, n-1)由于n很小(n<=20).

所以可以通过枚举法求前面的系数,然后C(n+k-1,n-1)利用逆元公式。

代码:

Codeforces 258 Div2的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. codeforces Round #258(div2) D解题报告

    D. Count Good Substrings time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  9. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

随机推荐

  1. Spark技术内幕:Stage划分及提交源码分析

    http://blog.csdn.net/anzhsoft/article/details/39859463 当触发一个RDD的action后,以count为例,调用关系如下: org.apache. ...

  2. Beyond Compare 相同文件对比结果仍显示红色 解决方案

    转载:http://blog.sina.com.cn/s/blog_4d4bc1110100zj7x.html   1. 问题详细描述如下. 下图显示对比结果中,两侧的aaa.xml是一模一样,会话中 ...

  3. 20160509-hibernate-集合映射

    集合映射 集合映射(set, list, array,bag, map) <set name=”employees” > <key column=”depart_id”/> & ...

  4. Flume负载均衡配置

    flume负载均衡配置 集群DNS配置如下: hadoop-maser 192.168.177.162 machine-0192.168.177.158 machine-1191.168.177.16 ...

  5. 偶尔会用到的有用的CMD命令

    1.解压CHM cd /d (如果你的chm文档在系统盘的话,就没有必要写这个/d) [你的chm文档的路径名] 回车 hh -decompile [源文件的保存路径] [要反编译的chm格式电子书] ...

  6. 第十二篇、HTML常用框架收集

    1.Swiper 广告轮播插件 2.Bootstrap 响应式布局 3.jQuery js兼容插件 4.jQuery Mobile 5.phoneGap

  7. eNSP

    L2交换机 sysvlan 200q interface Vlanif 200ip address 192.168.0.1 24dis thisq interface Ethernet 0/0/1po ...

  8. [java学习笔记]JDK的安装和环境变量的配置

    1.JDK的下载和安装 jdk(java development kit)是java提供给我们的一套java开发工具,它必运行在JVM(java虚拟机)上,java语言的跨平台性就是利用java运行在 ...

  9. 基本上,把switch,用设计模式代替,肯定是bug和过度设计。想想,本来修改一个文件几行代码可以解决的问题,变成修改3-6个类才能实现一样的功能。不是傻是什么?

    那些迷信设计模式的人,来修改一下这个方法吧.看看你最终的代码膨胀为几倍... public virtual PasswordChangeResult ChangePassword(ChangePass ...

  10. 在Mac OS X中使用VIM开发STM32(1)

       本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重!     在我先前的博文⎣在Mac OS X中搭建STM32开发环境⎤中,我们在Mac中DIY出了最 ...