A题:Opponents

直接模拟

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. char ch[];
  4. int main()
  5. {
  6. int n,k;
  7. while(~scanf("%d%d",&n,&k))
  8. {
  9. int p=,sta=,first=,ans;
  10. for(int i=;i<k;i++)
  11. {
  12. sta=;
  13. scanf("%s",ch);
  14. for(int i=;i<n;i++) sta&=(ch[i]-'');
  15. if(sta==) p++;
  16. if(sta==||(i==k-))
  17. {
  18. if(first) {ans=p;first=;}
  19. else
  20. {
  21. ans=max(ans,p);
  22. }
  23. p=;
  24. }
  25. }
  26. printf("%d\n",ans);
  27. }
  28. return ;
  29. }

B题: Lovely Palindromes
偶数长度的回文串
可以把这个回文串当做两半来处理,对于任何一个数字,只要把它反转后加到
数字尾,就可以形成一个回文串,且符合偶数长度的条件
既然任何数字都可以,那么第n个数就是以n来构造的

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Max=1e5+;
  4. char ch[Max];
  5. int main()
  6. {
  7. while(~scanf("%s",ch))
  8. {
  9. printf("%s",ch);
  10. reverse(ch,ch+strlen(ch));
  11. printf("%s\n",ch);
  12. }
  13. return ;
  14. }

C题:NP-Hard Problem
要求将一张图分成两个顶点集合,每个集合包含所有的边
要使得这样的集合成立,必须把每一条边上的两点分别分到两个集合中去
可以利用并查集分点,一个集合祖先节点小于等于n(小于等于(因为n+n))
另一个祖先节点大于n。
这两个集合有没有交集取决于同一条边上的两个顶点不能在同一集合

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Max=1e5+;
  4. int fa[Max*];
  5. int find(int x)
  6. {
  7. return fa[x]==-?x:fa[x]=find(fa[x]);
  8. }
  9. void Union(int x,int y)
  10. {
  11. int f1=find(x),f2=find(y);
  12. if(f1!=f2) fa[f1]=f2;
  13. }
  14. vector<int>ans1,ans2;
  15. int vis[Max];
  16. int main()
  17. {
  18. int n,m;
  19. while(~scanf("%d%d",&n,&m))
  20. {
  21. memset(fa,-,sizeof(fa));
  22. memset(vis,,sizeof(vis));
  23. int u,v,flag=;
  24. for(int i=;i<=m;i++)
  25. {
  26. scanf("%d%d",&u,&v);
  27. if(find(u)==find(v)) flag=; //两个顶点已经在同一集合,无解
  28. Union(u,v+n);
  29. Union(u+n,v);
  30. vis[u]=vis[v]=;
  31. }
  32. ans1.clear();ans2.clear();
  33. for(int i=;i<=n;i++)
  34. {
  35. if(!vis[i]) continue;
  36. if(find(i)<=n) ans1.push_back(i);
  37. else ans2.push_back(i);
  38. }
  39. if(ans1.empty()||ans2.empty()||flag) puts("-1");
  40. else
  41. {
  42. if(ans1.size()>ans2.size()) swap(ans1,ans2);
  43. printf("%d\n",ans1.size());
  44. for(int i=;i<ans1.size();i++)
  45. {
  46. if(i) printf(" ");
  47. printf("%d",ans1[i]);
  48. }
  49. printf("\n%d\n",ans2.size());
  50. for(int i=;i<ans2.size();i++)
  51. {
  52. if(i) printf(" ");
  53. printf("%d",ans2[i]);
  54. }
  55. puts("");
  56. }
  57. }
  58. return ;
  59. }

同样地,既然已经知道了解这道题的关键就是让每一条边的两个点分散到
两个不同的集合里面,那么直接dfs进行染色也是一个简洁易写的方法

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Max=1e5+;
  4. vector<int>G[Max];
  5. vector<int>ans1,ans2;
  6. int vis[Max],col[Max];
  7. bool dfs(int u,int c,int pre)
  8. {
  9. col[u]=c;
  10. int v;
  11. for(int i=;i<G[u].size();i++)
  12. {
  13. v=G[u][i];
  14. if(v==pre) continue;
  15. if(col[v]==c) return ;
  16. if(col[v]!=-) continue;
  17. if(!dfs(v,!c,u)) return ;
  18. }
  19. return ;
  20. }
  21. int main()
  22. {
  23. int n,m;
  24. while(~scanf("%d%d",&n,&m))
  25. {
  26. memset(vis,,sizeof(vis));
  27. memset(col,-,sizeof(col));
  28. int u,v;
  29. for(int i=;i<=m;i++)
  30. {
  31. scanf("%d%d",&u,&v);
  32. G[u].push_back(v);
  33. G[v].push_back(u);
  34. vis[u]=vis[v]=;
  35. }
  36. int root,flag=;
  37. for(int i=;i<=n;i++) if(vis[i])
  38. {
  39. root=i;
  40. if(col[root]!=-) continue;
  41. if(!dfs(root,,)) flag=;
  42. }
  43. if(flag) puts("-1");
  44. else
  45. {
  46. ans1.clear();ans2.clear();
  47. for(int i=;i<=n;i++)
  48. {
  49. if(col[i]==) ans1.push_back(i);
  50. if(col[i]==) ans2.push_back(i);
  51. }
  52. if(ans1.size()>ans2.size()) swap(ans1,ans2);
  53. printf("%d\n",ans1.size());
  54. for(int i=;i<ans1.size();i++)
  55. {
  56. if(i) printf(" ");
  57. printf("%d",ans1[i]);
  58. }
  59. printf("\n%d\n",ans2.size());
  60. for(int i=;i<ans2.size();i++)
  61. {
  62. if(i) printf(" ");
  63. printf("%d",ans2[i]);
  64. }
  65. puts("");
  66. }
  67. }
  68. return ;
  69. }

D题:Remainders Game
已知:
x mod c1 = m1
x mod c2 = m2
......
x mod cn = mn
这里要求知道x mod (k)的值,那么就要求lcm(c1,c2,c3,.....,cn)==k,并且ci之间互质

  1. #include <bits/stdc++.h>
  2. #define scan(x,y) scanf("%d%d",&x,&y)
  3. using namespace std;
  4. typedef long long LL;
  5. const int Max=1e5+;
  6. int n,m;
  7. LL gcd(LL a,LL b)
  8. {
  9. return b==?a:gcd(b,a%b);
  10. }
  11. int main()
  12. {
  13. scan(n,m);
  14. LL ans=;
  15. int x;
  16. for(int i=;i<=n;i++)
  17. {
  18. scanf("%d",&x);
  19. ans=gcd((LL)m,ans*(LL)x/gcd(ans,x));
  20. }
  21. if(ans==(LL)m) cout<<"Yes"<<endl;
  22. else cout<<"No"<<endl;
  23. return ;
  24. }

E题:The Values You Can Make
有n个价值不一的硬币,问能够凑出的所有面值(<=m)
dp[i][j],意为已经拥有j面值的情况下,能否凑成j面值
1.dp[0][0]=1
2.if(dp[l-x][j]) dp[l][j]=1 and dp[l][j+x]=1;
3.已拥有的硬币转移方向应该从大到小,因为用一枚硬币不能使用多次,不能对后面的
数值持续影响

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int Max=+;
  4. short dp[Max][Max];
  5. vector<int>ans;
  6. int main()
  7. {
  8. int n,k;
  9. while(~scanf("%d%d",&n,&k))
  10. {
  11. memset(dp,,sizeof(dp));
  12. dp[][]=;
  13. int x;
  14. for(int i=;i<n;i++)
  15. {
  16. scanf("%d",&x);
  17. for(int l=k;l>=x;l--)
  18. {
  19. for(int r=;r<=k-x;r++)
  20. {
  21. if(dp[l-x][r]) dp[l][r]=dp[l][r+x]=;
  22. }
  23. }
  24. }
  25. ans.clear();
  26. for(int i=;i<=k;i++)
  27. {
  28. if(dp[k][i]) ans.push_back(i);
  29. }
  30. printf("%d\n",ans.size());
  31. for(int i=;i<ans.size();i++)
  32. {
  33. if(i) printf(" ");
  34. printf("%d",ans[i]);
  35. }
  36. puts("");
  37. }
  38. return ;
  39. }

套题 codeforces 360的更多相关文章

  1. 套题 codeforces 359

    A题:Free Ice Cream 注意要使用LL,避免爆int #include <bits/stdc++.h> #define scan(x,y) scanf("%d%d&q ...

  2. 套题 codeforces 361

    A题((Mike and Cellphone) 看起来好像需要模拟数字键位的运动,可是,只要判断出那些必然YES的数字组合不就好了么 #include <cstdio> #include ...

  3. 套题 Codeforces Round #277 (Div. 2)

    A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...

  4. Educational Codeforces Round 15 套题

    这套题最后一题不会,然后先放一下,最后一题应该是大数据结构题 A:求连续最长严格递增的的串,O(n)简单dp #include <cstdio> #include <cstdlib& ...

  5. [codeforces 360]A. Levko and Array Recovery

    [codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...

  6. 第46套题【STL】【贪心】【递推】【BFS 图】

    已经有四套题没有写博客了.今天改的比较快,就有时间写.今天这套题是用的图片的形式,传上来不好看,就自己描述吧. 第一题:单词分类 题目大意:有n个单词(n<=10000),如果两个单词中每个字母 ...

  7. 【套题】qbxt国庆刷题班D1

    Day1 事实上D1的题目还是比较简单的= =然而D1T2爆炸了就十分尴尬--错失一波键盘 看题 T1 传送门 Description 现在你手里有一个计算器,上面显示了一个数\(S\),这个计算器十 ...

  8. Moscow Pre-Finals Workshop 2016. Japanese School OI Team Selection. 套题详细解题报告

    写在前面 谨以此篇题解致敬出题人! 真的期盼国内也能多出现一些这样质量的比赛啊.9道题中,没有一道凑数的题目,更没有码农题,任何一题拿出来都是为数不多的好题.可以说是这一年打过的题目质量最棒的五场比赛 ...

  9. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

随机推荐

  1. FMDB中 databaseWithPath 的使用问题

    阅读fmdb的源码文件(下载地址http://github.com/ccgus/fmdb)会发现下面一段注释,里面提到的创建数据库的方法也在很多博客中被引用,但是跑代码的时候发现,文件并不会像文档中所 ...

  2. ios UILabel在storyBoard或xib中如何在每行文字不显示完就换行

    大家知道怎么用代码让label中的文字换行,只需要 label.numberOfLines = 0; label.text = @"这是第一行啦啦啦啦,\n这是第二行啦啦,\n这是第三行&q ...

  3. generator class 的含义

    native有天生的,本土的,也就是说生来就有的, 那也就是说自动生成,不需要人工来帮忙或者管控的. 而assigned是指指定的,分配的, 如果你不赋予他甚麼东西,那麼他是不能实现的. 需要人工,自 ...

  4. atoi()函数

    原型:int  atoi (const  char  *nptr) 用法:#include  <stdlib.h> 功能:将字符串转换成整型数:atoi()会扫描参数nptr字符串,跳过前 ...

  5. 网络-->监控-->单位换算

    The metric system In some cases when used to describe data transfer rates bits/bytes are calculated ...

  6. 淌水 UE4的shootergame 案例 准备

    从毕业到现在,从GIS到游戏. 先记录一下cesium源码研究停止了一个多月了,还是有点放不下,等有机会一定研究透彻.感谢一下法克鸡丝博主. 好,研究了近两个月的游戏整体制作,熟悉了maya\unfl ...

  7. codeforces 446C DZY Loves Fibonacci Numbers 线段树

    假如F[1] = a, F[2] = B, F[n] = F[n - 1] + F[n - 2]. 写成矩阵表示形式可以很快发现F[n] = f[n - 1] * b + f[n - 2] * a. ...

  8. web测试

    1.验证码在不同浏览器兼容性(兼容测试) 2.登录时间cookie及session

  9. 下拉框数据的动态选择,类似级联ajax刷新数据

    简单的两个下拉列表,第二个中的数据与第一个下拉框相关: --------------------var selected = $(this).children('option:selected').v ...

  10. SQL 订阅发布备注

    单个用户问题 use mastergodeclare @SQL varchar(max)set @SQL=''select @SQL=@SQL+';kill '+RTRIM(spid)from mas ...