Codeforces Round #306 (Div. 2) 550A Two Substrings
链接: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的更多相关文章
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- 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 ...
- 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 ...
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad
题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...
- 「日常训练」Two Substrings(Codeforces Round 306 Div.2 A)
题意与分析 一道非常坑的水题.分析醒了补. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back ...
- 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 ...
- 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 ...
- 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/ ...
随机推荐
- Oracle中文乱码解决
查看当前Oracle字符集 select userenv('language') from dual; USERENV('LANGUAGE') ---------------------------- ...
- docker快速安装jenkins
用过docker的人,可能真的很难忍受再一步步二进制安装了,好了话不多说,感慨一下jenkins实现自动化发布构建真的很方便. 推荐一个学习的好地方https://m.w3cschool.cn/jen ...
- python导包学习总结
python初学者,对于导包纠结了不少时间,总结分享,持续前进~ Python导包的两种方法: 1.1 from 包.模块 import 方法名,调用时直接使用方法名() 1.2 from 包. ...
- E - Nature Reserve CodeForces - 1059D
传送门 There is a forest that we model as a plane and live nn rare animals. Animal number iihas its lai ...
- Nginx技术深入剖析
Nginx软件功能模块说明 核心功能模块(Core functionality):主要对应配置文件的Main区块和Events区块. 标准的http功能模块: 企业 场景常用的Nginx http功能 ...
- POJ:2377-Bad Cowtractors
传送门:http://poj.org/problem?id=2377 Bad Cowtractors Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- react+redux状态管理实现排序 合并多个reducer文件
这个demo只有一个reducer 所以合并reducer这个demo用不到 ,但是我写出来这样大家以后可以用到,很好用,管理多个reducer,因为只要用到redux就不会只有一个reducer所以 ...
- PHP.13-日历类实现
日历类实现 1.输出星期 calendar.class.php <?php class Calendar{ function out(){//输出表格 echo '<table align ...
- HDFS写数据和读数据流程
HDFS数据存储 HDFS client上传数据到HDFS时,首先,在本地缓存数据,当数据达到一个block大小时.请求NameNode分配一个block. NameNode会把block所在的Dat ...
- 洛谷P1605 迷宫
迷宫 题目链接 这道题就是一道简单的dfs计方案数qwq. 我的思路是把表初始化为1,再将障碍改为0,因为在全局定义中数组会直接初始化为0,所以就少去了对边界的特判. next数组加循环可以减少代码量 ...