CF 420A  A. Start Up

题目链接:

http://codeforces.com/problemset/problem/420/A

题目意思:

给一个字符串A,通过镜面反射后得到A‘,推断A和A’是否全然一样。

解题思路:

水题。分析知有些字母通过镜面反射后和原来一样。

代码:

  1. //#include<CSpreadSheet.h>
  2.  
  3. #include<iostream>
  4. #include<cmath>
  5. #include<cstdio>
  6. #include<sstream>
  7. #include<cstdlib>
  8. #include<string>
  9. #include<string.h>
  10. #include<cstring>
  11. #include<algorithm>
  12. #include<vector>
  13. #include<map>
  14. #include<set>
  15. #include<stack>
  16. #include<list>
  17. #include<queue>
  18. #include<ctime>
  19. #include<bitset>
  20. #include<cmath>
  21. #define eps 1e-6
  22. #define INF 0x3f3f3f3f
  23. #define PI acos(-1.0)
  24. #define ll __int64
  25. #define LL long long
  26. #define lson l,m,(rt<<1)
  27. #define rson m+1,r,(rt<<1)|1
  28. #define M 1000000007
  29. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  30. using namespace std;
  31.  
  32. #define Maxn 33
  33. int hav[Maxn];
  34. char save[110000];
  35.  
  36. void init()
  37. {
  38. memset(hav,0,sizeof(hav));
  39. hav[1]=1,hav['H'-'A'+1]=1;
  40. hav['I'-'A'+1]=1;
  41. hav['M'-'A'+1]=1;
  42. hav['O'-'A'+1]=1;
  43. hav['T'-'A'+1]=1;
  44. hav['U'-'A'+1]=1;
  45. hav['V'-'A'+1]=1;
  46. hav['W'-'A'+1]=1;
  47. hav['X'-'A'+1]=1;
  48. hav['Y'-'A'+1]=1;
  49.  
  50. }
  51. int main()
  52. {
  53. //freopen("in.txt","r",stdin);
  54. //freopen("out.txt","w",stdout);
  55. while(~scanf("%s",save+1))
  56. {
  57. int len=strlen(save+1);
  58. int ans=1;
  59. int p=1;
  60.  
  61. init();
  62.  
  63. //printf("%d %d\n",p,len);
  64. while(save[p]==save[len]&&p<=len)
  65. {
  66. if(!hav[save[p]-'A'+1])
  67. {
  68. ans=0;
  69. break;
  70. }
  71. p++;
  72. len--;
  73. }
  74.  
  75. if(p<=len)
  76. ans=0;
  77. if(ans)
  78. printf("YES\n");
  79. else
  80. printf("NO\n");
  81. }
  82. return 0;
  83. }

CF 420B B. Online Meeting

题目链接:

http://codeforces.com/problemset/problem/420/B

题目意思:

有n个人开会,已知按时间顺序的m个进出记录(部分开会),求哪些人可能一直在开会。

解题思路:

抽象模拟。

能够保存一个当前时间的统治者me.

(无)+(有)

(有)-(无)

详解请见代码:

  1. //#include<CSpreadSheet.h>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<cstdio>
  5. #include<sstream>
  6. #include<cstdlib>
  7. #include<string>
  8. #include<string.h>
  9. #include<cstring>
  10. #include<algorithm>
  11. #include<vector>
  12. #include<map>
  13. #include<set>
  14. #include<stack>
  15. #include<list>
  16. #include<queue>
  17. #include<ctime>
  18. #include<bitset>
  19. #include<cmath>
  20. #define eps 1e-6
  21. #define INF 0x3f3f3f3f
  22. #define PI acos(-1.0)
  23. #define ll __int64
  24. #define LL long long
  25. #define lson l,m,(rt<<1)
  26. #define rson m+1,r,(rt<<1)|1
  27. #define M 1000000007
  28. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  29. using namespace std;
  30.  
  31. #define Maxn 110000
  32.  
  33. int ans[Maxn],add[Maxn];
  34. int n,m,a,cnt,me;
  35. char temp[3];
  36.  
  37. int main()
  38. {
  39. //freopen("in.txt","r",stdin);
  40. //freopen("out.txt","w",stdout);
  41. while(~scanf("%d%d",&n,&m))
  42. {
  43. for(int i=1;i<=n;i++)
  44. ans[i]=1,add[i]=0;;
  45. cnt=0;
  46. me=0;
  47.  
  48. for(int i=1;i<=m;i++)
  49. {
  50. scanf("%s%d",temp,&a);
  51. if(*temp=='+')
  52. {
  53. if(!me||(me==a)) //更新统治者 注意要分别 +1 -1 +1的情况。此时统治者还是1
  54. me=a;
  55. else
  56. ans[a]=0; //和前面的通知不一样 不行 比方+1 +2那么2不行
  57. add[a]=1; //保存出现
  58.  
  59. if(a!=me&&!add[me]) //-1 +2 此时的1不行
  60. ans[me]=0;
  61. cnt++;
  62. }
  63. else //'-'
  64. {
  65. if(!me) //更新统治者
  66. me=a;
  67. if(a!=me&&add[a]==0) //+1 +2 -3 此时1为统治者
  68. {
  69. ans[me]=0;
  70. me=a;
  71. }
  72. if(add[a]) //抵消
  73. {
  74. add[a]=0;
  75. cnt--;
  76. }
  77. if(cnt) //还有剩余力量 +1 +2 -2 此时的2不行 +1 +2 -1此时的1也不行,仅仅要有+的不一样就不行
  78. ans[a]=0;
  79.  
  80. }
  81.  
  82. }
  83. int tt=0;
  84. bool fi=true;
  85.  
  86. for(int i=1;i<=n;i++)
  87. if(ans[i])
  88. tt++;
  89. printf("%d\n",tt);
  90. for(int i=1;i<=n;i++)
  91. {
  92. if(ans[i])
  93. {
  94. if(!fi) //第一个出现
  95. printf(" ");
  96. printf("%d",i);
  97. if(fi)
  98. fi=false;
  99. }
  100.  
  101. }
  102. printf("\n");
  103.  
  104. }
  105. return 0;
  106. }
  1. Codeforces 420C - Bug in Code
  2. 题目链接:
  3. http://codeforces.com/problemset/problem/420/C
  4. 解题思路:
  5. 先预处理出当选中第i个人时,会使num[i]个人惬意。注意当(i,j)是某人同一时候讨厌的时候,假设此时选中(i,j)仅仅会使一个人惬意。所以先出于处理出这样的情况,直接推断出选中(i,j)时是否可行。假设不行提前减掉。
  6.  
  7. 然后再排序,枚举选中的第一个人,直接二分出第二个人的位置。
  8. 代码:
  1. //#include<CSpreadSheet.h>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<cstdio>
  5. #include<sstream>
  6. #include<cstdlib>
  7. #include<string>
  8. #include<string.h>
  9. #include<cstring>
  10. #include<algorithm>
  11. #include<vector>
  12. #include<map>
  13. #include<set>
  14. #include<stack>
  15. #include<list>
  16. #include<queue>
  17. #include<ctime>
  18. #include<bitset>
  19. #include<cmath>
  20. #define eps 1e-6
  21. #define INF 0x3f3f3f3f
  22. #define PI acos(-1.0)
  23. #define ll __int64
  24. #define LL long long
  25. #define lson l,m,(rt<<1)
  26. #define rson m+1,r,(rt<<1)|1
  27. #define M 1000000007
  28. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  29. using namespace std;
  30. #define Maxn 310000
  31. int num[Maxn],n,p;
  32. map<pair<int,int>,int>myp;
  33. int main()
  34. {
  35.    //freopen("in.txt","r",stdin);
  36.    //freopen("out.txt","w",stdout);
  37.    while(~scanf("%d%d",&n,&p))
  38.    {
  39.        memset(num,0,sizeof(num));
  40.        myp.clear();
  41.        for(int i=1;i<=n;i++)
  42.        {
  43.            int a,b;
  44.            scanf("%d%d",&a,&b);
  45.            if(a>b)
  46.                 swap(a,b);
  47.            myp[make_pair(a,b)]++;
  48.            num[a]++;
  49.            num[b]++;
  50.        }
  51.        map<pair<int,int>,int>::iterator it=myp.begin();
  52.        ll ans=0;
  53.        for(;it!=myp.end();it++)
  54.        {
  55.            int ta=it->first.first,tb=it->first.second;
  56.            if(num[ta]+num[tb]>=p&&num[ta]+num[tb]-it->second<p)
  57.                 ans--;  //说明选中ta和tb不可行
  58.        }
  59.        sort(num+1,num+n+1);
  60.        for(int i=1;i<n;i++)
  61.        {
  62.           /* if(!num[i])
  63.                 continue;*/
  64.            if(num[i]>=p)
  65.            {
  66.                ans+=n-i;
  67.                continue;
  68.            }
  69.            int temp=p-num[i];
  70.            if(temp>num[n]) //二分出第二个人的位置
  71.                 continue;
  72.            int pos=lower_bound(num+i+1,num+n+1,temp)-num;
  73.            ans+=n-pos+1;
  74.            //printf("i:%d pos:%d\n",i,pos);
  75.        }
  76.        printf("%I64d\n",ans);
  77.    }
  78.    return 0;
  79. }
  80.  

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Coder-Strike 2014 - Finals (online edition, Div. 1)的更多相关文章

  1. Coder-Strike 2014 - Finals (online edition, Div. 2) A. Pasha and Hamsters

    水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...

  2. Coder-Strike 2014 - Finals (online edition, Div. 2) B. Start Up

    需要满足的条件是 (1)每个字母是对称的 (2)每个字符串是对称的 #include <iostream> #include <algorithm> #include < ...

  3. Coder-Strike 2014 - Finals (online edition, Div. 2) C题

    C. Online Meeting time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】

    Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...

  5. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing

    B. Bear and Compressing 题目链接  Problem - B - Codeforces   Limak is a little polar bear. Polar bears h ...

  6. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表

    E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...

  7. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树

    E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...

  8. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流

    D. Delivery Bears 题目连接: http://www.codeforces.com/contest/653/problem/D Description Niwel is a littl ...

  9. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力

    C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes ...

随机推荐

  1. 2、Cocos2dx 3.0游戏开发找小三之引擎简单介绍

    尊重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27094663 引擎简单介绍 Cocos2d-x 的 ...

  2. Lucene学习总结之五:Lucene段合并(merge)过程分析 2014-06-25 14:20 537人阅读 评论(0) 收藏

    一.段合并过程总论 IndexWriter中与段合并有关的成员变量有: HashSet<SegmentInfo> mergingSegments = new HashSet<Segm ...

  3. 提高编程能力的7条建议 分类: T_TALENT 2014-04-12 10:41 294人阅读 评论(0) 收藏

    编程是非常酷的一件事情,但是在酷炫的背后它对很多人来说还是挺难的.很多人在学习编程之初就被困难击败了. 当你不熟悉编程的时候,你可能会觉得无从下手,并且不知道如何运用学到的知识.只要你通过了这一困难的 ...

  4. 使用Apache FtpServer搭建FTP服务器 [FlashFXP]

    <server xmlns="http://mina.apache.org/ftpserver/spring/v1" xmlns:xsi="http://www.w ...

  5. js判断是否微信客户端

    上周接到个需求,需求是这样的:用户扫一扫二维码会产生一个链接,该链接会向后端发送个请求,返回一个 apk 的下载地址,用户点击下载按钮可以下载此 apk.然后就发生了问题,经过测试,发现用微信扫一扫打 ...

  6. C# 使用 RabbitMQ

    1. RabbitMQ MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过写和检索出入列队的针对应用程序的数据(消息)来通信,而无需专用连接来链接 ...

  7. [Now] Configure secrets and environment variables with Zeit’s Now

    Often your project will require some secret keys or tokens - for instance, API keys or database auth ...

  8. Deepin下python安装uwsgi报错: Python.h:没有那个文件或目录

    解决方法是安装python-dev,这是Python的头文件和静态库包 正在读取软件包列表... 完成正在分析软件包的依赖关系树       正在读取状态信息... 完成       下列软件包是自动 ...

  9. Word2010中插入多级列表编号

    https://jingyan.baidu.com/article/3ea5148901919752e61bbafe.html Word2010中插入多级列表编号的三种方法 听语音 | 浏览:8719 ...

  10. Http请求工具类(Java原生Form+Json)

    package com.tzx.cc.common.constant.util; import java.io.IOException; import java.io.InputStream; imp ...