链接:http://codeforces.com/contest/550/problem/A

这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的。

所以看到这道题我果断觉得是拼手速的题啊,结果瞬间就一发WA,连pretest都没通过,

然后开始想,发现没那么简单的样子,很多坑的样子,当我写了2个循环把AB BA 都扫一遍时,

认为考虑周全后,觉得能过了,就交,过了pretest,当时看room里面 大多数还没过A呢,觉得很高兴。

然后学长说这题能叉很多人,我不懂什么是叉,后来才知道原来这就是所谓的hack。学长给我数据叫我去hack

别人,说这数据绝对能hack很多人,还截图给我 他们room好多都被他hack了。我点开许多人的代码,各种语言都有的,

看来看去感觉都能过啊,就没去hack了,因为才做了一题,还要做下面的题目。结果当我过了第二题时,突然弹出我被hack的消息。。。

我还想去resubmmit呢,不懂规则也是悲剧啊。把C题不考虑的写了写,交过了pretest,觉得圆满了,谁知道原来这只是部分数据了。

打完第一次cf,懂了很多规则,的确很刺激,好玩,下面就讲A题了。

我搞来搞去,觉得分情况是最保险的了,因为情况数比较少。

扫一遍 得到AB  和 BA的个数a,b

1:如果a,b有一个为0 那么NO

2:如果a ,b都为1 ,那么在原串中找是否存在子串ABA 或者BAB 存在 NO,否则 YES

3:如果a,b中有一个为1,另一个为2,找是否存在子串ABAB,或者BABA 存在NO 否则YES

4如果 a,b >=2 那么不会存在覆盖的问题,YES

代码如下

 1 #include<stdio.h>
2 #include<iostream>
3 #include<cstring>
4 #include<stack>
5 #include<queue>
6 #include<ctype.h>
7 #include<math.h>
8 #include<algorithm>
9 #include<string.h>
10 #include<set>
11 using namespace std;
12 const int maxn = 1e5+5;
13 char s[maxn];
14 int main()
15 { int a = 0,b = 0;
16 cin>>s;
17 int len = strlen(s);
18 for(int i = 0;i<len;i++)
19 {
20 if(s[i]=='A'&&s[i+1]=='B') a++;
21 if(s[i]=='B'&&s[i+1]=='A') b++;
22 }
23 if(!a||!b) puts("NO");
24 else
25 {
26 if(a==1&&b==1)
27 {
28 if(strstr(s,"ABA")||strstr(s,"BAB")) puts("NO");
29 else puts("YES");
30 }
31 else if(a==2&&b==1&&strstr(s,"ABAB")) puts("NO");
32 else if(b==2&&a==1&&strstr(s,"BABA")) puts("NO");
33 else puts("YES");
34 }
35
36 return 0;
37 }

Codeforces Round #306 (Div. 2) 550A Two Substrings的更多相关文章

  1. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  2. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  3. Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】

    A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  5. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  6. 「日常训练」Two Substrings(Codeforces Round 306 Div.2 A)

    题意与分析 一道非常坑的水题.分析醒了补. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back ...

  7. Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  8. Codeforces Round #306 (Div. 2) D. Regular Bridge 构造

    D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  9. Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力

    C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

随机推荐

  1. ES6初识-Proxy和Reflect

    { let obj={ time:'2017-03-11', name:'net', _r:123 };   let monitor=new Proxy(obj,{ // 拦截对象属性的读取 get( ...

  2. c# .net 3.5 4.0 4.5 5.0 6.0各个版本新特性战略规划总结【转载】

    引用:http://blog.csdn.net/attilax/article/details/42014327 c# .net 3.5 4.0 各个版本新特性战略规划总结 1. ---------- ...

  3. hive连接MySQL报错

    错误如下: [root@awen01 /usr/local/apache-hive-1.2.1-bin]#./bin/hive Logging initialized using configurat ...

  4. PAT (Basic Level) Practice 1021 个位数统计

    个人练习 给定一个 k 位整数 N=d​k−1​​10​k−1​​+⋯+d​1​​10​1​​+d​0​​ (0≤d​i​​≤9, i=0,⋯,k−1, d​k−1​​>0),请编写程序统计每种 ...

  5. 11.2,nginx负载均衡实验

    Nginx负载均衡概述 Web服务器,直接面向用户,往往要承载大量并发请求,单台服务器难以负荷,我使用多台WEB服务器组成集群,前端使用Nginx负载均衡,将请求分散的打到我们的后端服务器集群中,实现 ...

  6. CSS3裁剪与遮罩解析

    一.用途 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分而显示另一部分 二.区别 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分 ...

  7. poj2001Shortest Prefixes(trie)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18687   Accepted: 808 ...

  8. Fiddler - 使用教程

    1.断点调试,修改请求表单和响应数据 命令介绍: bpu在请求开始时中断,bpafter在响应到达时中断,bps在特定http状态码时中断,bpv/bpm在特定请求method时中断. bpu m.t ...

  9. 为什么rows这么大,在mysql explain中---写在去acumg听讲座的前一夜

    这周五下班前,发现了一个奇怪问题,大概是这个背景 一张表,结构为 Create Table: CREATE TABLE `out_table` ( `id` ) NOT NULL AUTO_INCRE ...

  10. .gitignore 中文文件夹无效

    有个文件夹名如:测试 在.gitignore中添加  /测试/   但运行命令git status后发现还是被追踪到了 一番搜索后终于发现.gitignore文件编码是GBK的,重新将文件保存成utf ...