A. Sasha and Sticks

题目链接:http://codeforces.com/contest/832/problem/A

题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sasha先取,问Sasha是否可以取胜。

代码:

  1. //Author: xiaowuga
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <set>
  5. #include <vector>
  6. #include <queue>
  7. #include <cmath>
  8. #include <cstring>
  9. #include <cstdio>
  10. #include <ctime>
  11. #include <map>
  12. #include <bitset>
  13. #include <cctype>
  14. #define maxx INT_MAX
  15. #define minn INT_MIN
  16. #define inf 0x3f3f3f3f
  17. #define mem(s,ch) memset(s,ch,sizeof(s))
  18. const long long N=;
  19. using namespace std;
  20. typedef long long LL;
  21. int main() {
  22. ios::sync_with_stdio(false);cin.tie();
  23. LL n,k;
  24. LL ct;
  25. cin>>n>>k;
  26. if(n%k==){
  27. ct=n/k;
  28. }
  29. else ct=n/k;
  30. if(ct%){cout<<"YES"<<endl;}
  31. else cout<<"NO"<<endl;
  32. return ;
  33. }

B. Petya and Exam

题目链接:http://codeforces.com/contest/832/problem/B

题目意思:一个xjb大模拟。第一行是好字符(26个),除此之外都是坏字符,第二行是B字符串,B中问号可以change为好字符,* 只能change为坏字符串(字符可以有可以0~MAX个),接下来n次询问,每次给出目标C字符串,问B可以change为C么?

思路:这个题真的wa了很多发啊…………,分四种情况:1.询问串长度大于模式串且差大于1;2.询问串长度大于模式串且差等于1,3.询问串长度等于模式串;4.询问串长度小于模式串。

其中在情况1的时候,还要判断是否出现过*,因为可能没有出现过*,整体的思路就是先把*代表东西补出来,然后安慰比较久可以了。

代码:

  1. //Author: xiaowuga
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <set>
  5. #include <vector>
  6. #include <queue>
  7. #include <cmath>
  8. #include <cstring>
  9. #include <cstdio>
  10. #include <ctime>
  11. #include <map>
  12. #include <bitset>
  13. #include <cctype>
  14. #define maxx INT_MAX
  15. #define minn INT_MIN
  16. #define inf 0x3f3f3f3f
  17. #define mem(s,ch) memset(s,ch,sizeof(s))
  18. const long long N=1e5+;
  19. using namespace std;
  20. char a[N],b[N];
  21. int la,lb,lc,lm;
  22. int check[]={};
  23. typedef long long LL;
  24. int main() {
  25. ios::sync_with_stdio(false);cin.tie();
  26. cin>>a>>b;
  27. la=strlen(a);lb=strlen(b);
  28. for(int i=;i<la;i++) check[a[i]-'a']=;
  29. int n;
  30. cin>>n;
  31. while(n--){
  32. char c[N];cin>>c;
  33. int lc=strlen(c);
  34. lm=lb-lc;
  35. int flag=;
  36. if(lm>) {cout<<"NO"<<endl;continue;}
  37. else if(lm==){
  38. int h=;
  39. for(int i=;i<lb;i++) if(b[i]=='*') {h=;break;}
  40. if(h){
  41. for(int i=,j=;j<lc;i++){
  42. if(b[i]=='*') {continue;}
  43. else if(b[i]=='?'){
  44. if(check[c[j]-'a']==) {flag=;break;}
  45. }
  46. else if(b[i]!=c[j]){
  47. flag=; break;
  48. }
  49. j++;
  50. }
  51. }
  52. else flag=;
  53.  
  54. }
  55. else if(lm==){
  56. for(int i=;i<lb;i++){
  57. if(b[i]=='*'||b[i]=='?'){
  58. if(b[i]=='*'){
  59. if(check[c[i]-'a']){flag=;break;}
  60. }
  61. else{
  62. if(check[c[i]-'a']==){flag=;break;}
  63. }
  64. }
  65. else if(b[i]!=c[i]){flag=;break;}
  66. }
  67. }
  68. else if(lm<){
  69. char mb[N];
  70. lm=-lm+;
  71. //cout<<lm<<endl;
  72. int ct=;
  73. for(int i=,j=;i<lb;i++){
  74. if(b[i]=='*'){
  75. for(int k=;k<lm;k++){
  76. if(check[c[j]-'a']){ mb[ct++]='?';}
  77. else mb[ct++]=c[j++];
  78. }
  79. continue;
  80. }
  81. else if(b[i]=='?'){
  82. if(check[c[j]-'a']) mb[ct++]=c[j];
  83. else mb[ct++]='?';
  84. }
  85. else if(b[i]!=c[j]) { mb[ct++]=b[i];}
  86. else mb[ct++]=c[j];
  87. j++;
  88. }
  89. if(ct<lc) flag=;
  90. else{
  91. for(int i=;i<lc;i++){
  92. if(mb[i]!=c[i]){
  93. flag=;break;
  94. }
  95. }
  96. }
  97. }
  98. if(flag) cout<<"YES"<<endl;
  99. else cout<<"NO"<<endl;
  100.  
  101. }
  102. return ;
  103. }

D. Misha, Grisha and Underground

题目链接:http://codeforces.com/contest/832/problem/D

题目意思:LCA模板题,可以数到标签的数量等于(dist(a,b)+dist(c,b)-dist(a,c))/2+1。两点之间的距离可以用LCA算出。这里LCA用的是基于DFS序的RMQ算法。

代码:

  1. //Author: xiaowuga
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <set>
  5. #include <vector>
  6. #include <queue>
  7. #include <cmath>
  8. #include <cstring>
  9. #include <cstdio>
  10. #include <ctime>
  11. #include <map>
  12. #include <bitset>
  13. #include <cctype>
  14. #define maxx INT_MAX
  15. #define minn INT_MIN
  16. #define inf 0x3f3f3f3f
  17. #define mem(s,ch) memset(s,ch,sizeof(s))
  18. #define nc cout<<"nc"<<endl
  19. const long long N=+;
  20. using namespace std;
  21. typedef long long LL;
  22. typedef int II;
  23. vector<int>p[N];
  24. II n,q;
  25. II fr[*N],de[*N],pos[*N],tot=;
  26. II d[N][];
  27. void RMQ_init(){
  28. for(II i=;i<=tot;i++) d[i][]=fr[i];
  29. for(II j=;(<<j)<=tot;j++)
  30. for(II i=;i+(<<j)-<=tot;i++){
  31. II x=d[i][j-];
  32. II y=d[i+(<<(j-))][j-];
  33. if(de[x]<de[y]) d[i][j]=x;
  34. else d[i][j]=y;
  35. }
  36. }
  37. II RMQ(II x,II y){
  38. II L=min(pos[x],pos[y]),R=max(pos[x],pos[y]);
  39. II k=log((double)(R-L+))/log(2.0);
  40. II t1=d[L][k];
  41. II t2=d[R-(<<k)+][k];
  42. if(de[t1]<de[t2]) return t1;
  43. else return t2;
  44. }
  45.  
  46. void dfs(II u,II pre,II dep){
  47. fr[++tot]=u;pos[u]=tot;de[u]=dep;
  48. for(II i=;i<p[u].size();i++){
  49. II v=p[u][i];
  50. if(v==pre) continue;
  51. dfs(v,u,dep+);
  52. fr[++tot]=u;
  53. }
  54. }
  55.  
  56. II dist(II x,II y){
  57. II qe=RMQ(x,y);
  58. int len=de[x]+de[y]-*de[qe];
  59. return len;
  60. }
  61. int main(){
  62. ios::sync_with_stdio(false);cin.tie();
  63. cin>>n>>q;
  64. for(II i=;i<=n;i++){
  65. II x;
  66. cin>>x;
  67. p[i].push_back(x);p[x].push_back(i);
  68. }
  69. dfs(,-,);
  70. RMQ_init();
  71. while(q--){
  72. II x,y,z;
  73. cin>>x>>y>>z;
  74. II t,ans=minn;
  75. II lxy=dist(x,y),lxz=dist(x,z),lyz=dist(y,z);
  76. t=(lxy+lyz-lxz)/+;//y为终点
  77. ans=max(t,ans);
  78. t=(lxy+lxz-lyz)/+;//x为终点
  79. ans=max(t,ans);
  80. t=(lxz+lyz-lxy)/+;//z为终点
  81. ans=max(t,ans);
  82. cout<<ans<<endl;
  83. }
  84. return ;
  85. }

Codeforces Round #425 (Div. 2))——A题&&B题&&D题的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  3. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  4. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  5. Codeforces Round #379 (Div. 2) A. Anton and Danik 水题

    A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...

  6. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  7. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  8. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  9. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

随机推荐

  1. Objective-C的内存管理(一)黄金法则的理解

    转自:http://blog.csdn.net/lonelyroamer/article/details/7666851 一.内存管理黄金法则: The basic rule to apple is ...

  2. int、char、long各占多少字节数

    Java基本类型占用的字节数:1字节: byte , boolean2字节: short , char4字节: int , float8字节: long , double 编码与中文:Unicode/ ...

  3. 219. Insert Node in Sorted Linked List【Naive】

    Insert a node in a sorted linked list. Example Given list = 1->4->6->8 and val = 5. Return  ...

  4. private继承的作用

    这里有个demo,里面的Stack<T*> : private Stack<void *>,作者对此的解释如下 The partial specialization for o ...

  5. jdom 插入 修改 删除

    创建XML文档 XML文件是一种典型的树形文件,每个文档元素都是一个document元素的子节点.而每个子元素都是一个Element对象,对象可以向下包含. 1 因此我们可以通过先创建元素再将元素添加 ...

  6. poj2559单调栈

    题意:给出连续的矩形的高....求最大面积 #include<iostream> #include<stack> #include<stdio.h> using n ...

  7. R ggplot2 翻转坐标

    p <- ggplot(mpg, aes(class, hwy)) p + geom_boxplot() p + geom_boxplot() + coord_flip()

  8. tiny4412 u-boot 启动参数的设置

    参考 http://www.cnblogs.com/chenfulin5/p/5887552.html 制作SD卡 u-boot 编译完之后, 进入 u-boot 目录里面的 sd_fuse cd ~ ...

  9. 数据库事务隔离级别<转>

    数据库事务的隔离级别有4个,由低到高依次为Read uncommitted.Read committed.Repeatable read.Serializable,这四个级别可以逐个解决脏读.不可重复 ...

  10. 在ubuntu下安装sourceinsight

    执行更新与安装 wine: # sudo apt-get update # sudo apt-get install wine 下载SourceInsight,用wine来安装: 执行:wine so ...