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/ ...
随机推荐
- Python——列表
应用场景,要统计大量的人员信息.就可以用列表的形式进行.name = ['邱秀','玄永俊','杨栋豪']查:print(name[2],name[0]) #取号码进行识别print(name[1:3 ...
- MyFirstDay_答案_1.**猫(自己整理)
1>***猫: python基础类: 字符串反转的常用处理方式: # 方法一:使用字符串切片 s = "hello python" result = s[::-1] prin ...
- Ball CodeForces - 12D
传送门 N ladies attend the ball in the King's palace. Every lady can be described with three values: be ...
- ABAP自定义截取字符串长度函数
SAP 中strlen()只能计算字符串的个数,不能计算含有中文字符串的长度,如字符串“SAP大波霸”,strlen('SAP大波霸') = 6,其实真实长度为3+3*2 = 9.我们可以通过cl_a ...
- vue 组件轮播联动
组件轮播联动我使用的是 el-carousel 组件,具体代码如下: <el-carousel trigger="click" :interval="3000&qu ...
- Spark机器学习之推荐引擎
一. 最小二乘法建立模型 关于最小二乘法矩阵分解,我们可以参阅: 一.矩阵分解模型. 用户对物品的打分行为可以表示成一个评分矩阵A(m*n),表示m个用户对n各物品的打分情况.如下图所示: 其中,A( ...
- 12 Django组件-forms组件
forms组件 校验字段功能 针对一个实例:注册用户讲解. 模型:models.py class UserInfo(models.Model): name=models.CharField(max_l ...
- [bzoj3450]Tyvj1952Easy
瓜皮期望真是弱成渣.. 完全不理解的感觉qwq...题面%了一发千古神犇WJMZBMR哈~ Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化 ...
- ios在tableview里面加subview后在ip4和ip5上显示不一样的问题
文章链接:http://quke.org/post/ios-tableview-addsubview-height.html (转载时请注明本文出处及文章链接) 我在在tableview里面加subv ...
- Lua语言中文手册 转载自网络
Programming in LuaCopyright ® 2005, Translation Team, www.luachina.net Programming in LuaProgramming ...