最近是怎么了,老是掉分,sad = =.......

明明都会做,但一到比赛时,就没有想法了。。。估计是太困了吧。。。

A. Two Substrings
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

Sample test(s)
input
ABA

output
NO

input
BACFAB

output
YES

input
AXBYBXA

output
NO

Note

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".

这道题我看了好久,原因呢?我不知道它说的题目意思是两个字符串“AB"和”BA"就可以了,还是要分别都要两个,事后想想,这个愚蠢的问题。。。然后回过头看,wa~,完了,又要掉分了。。。

想法呢:

就是for4遍,首先第一遍是为了先找出AB有没有,然后for第二遍找出BA,记得把AB所在的位置要标记上;

然后如果上面找到两种字符串的话,那么就不用进行下面的语句了,但是没有找到,那么就要for先找出BA,然后就再去找AB,大致与上面找的方法相同。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define maxn 111111
map<string,int> mp;
char a[maxn];
int mp1[maxn],mp2[maxn];
int main(){scanf("%s",a);int len=strlen(a);int i,j,k,l;bool f1,f2;f1=f2=false;for(i=0;i<len;i++){if(a[i]=='A'&&a[i+1]=='B'&&i!=len-1) {mp1[i]=1; mp1[i+1]=1; f1=true; break;}}for(i=0;i<len;i++){if(a[i]=='B'&&a[i+1]=='A'&&!mp1[i]&&!mp1[i+1]&&i!=len-1) {f2=true; break;}}if(f1&&f2) printf("YES\n");else{f1=f2=false;memset(mp1,0,sizeof(mp1));memset(mp2,0,sizeof(mp2));for(i=0;i<len;i++){if(a[i]=='B'&&a[i+1]=='A'&&i!=len-1){mp1[i]=1; mp1[i+1]=1; f1=true; break;}}for(i=0;i<len;i++){if(a[i]=='A'&&a[i+1]=='B'&&!mp1[i]&&!mp1[i+1]&&i!=len-1){f2=true; break;}}if(f1&&f2) printf("YES\n");else printf("NO\n");}
}
B. Preparing Olympiad
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.

A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.

Find the number of ways to choose a problemset for the contest.

Input

The first line contains four integers nlrx (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

Output

Print the number of ways to choose a suitable problemset for the contest.

Sample test(s)
input
3 5 6 1
1 2 3

output
2

input
4 40 50 10
10 20 30 25

output
2

input
5 25 35 10
10 10 20 10 20

output
6

Note

In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.

In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.

In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

这道题我一开始没有想出来,后来看别人的想法做的,就是一个dfs。

题意就是给你限定了一个范围区间[l,r]; 然后你可以选n门课中的任意门然后要使它们的难度系数之和在这个区间范围内,然后在你所选的课中找出最大值max,最小值min,然后它们两个的差值要大于等于x才行,然后问你总共有几种选课的方法。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn  22
#define inf 99999999
int a[maxn],l,r,x,n;
int num=0;
void dfs(int cur,int sum,int ma,int mi,int cnt){if(sum>r) return;if(ma<a[cur]) ma=a[cur];if(mi>a[cur]) mi=a[cur];if(sum>=l&&sum<=r&&(ma-mi>=x)&&cnt>=2){num++;//return    注意了,这里并不用加return,因为我们这里并不需要返回,因为我们要做的就是让它不撞南墙不回头的去搜索!!! }for(int i=cur+1;i<n;i++){dfs(i,sum+a[i],ma,mi,cnt+1);}
}
int main(){scanf("%d%d%d%d",&n,&l,&r,&x);for(int i=0;i<n;i++) scanf("%d",&a[i]);//sort(a,a+n);num=0;//这里因为我们是从前往后依次搜过去,所以不用担心前面的情况没有被覆盖到,所以下面写成从i开始搜!! for(int i=0;i<n;i++){dfs(i,a[i],-1,inf,1);}printf("%d\n",num);
}
C. Divisibility by Eight
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

Output

Print "NO" (without quotes), if there is no such way to remove some digits from number n.

Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Sample test(s)
input
3454

output
YES
344

input
10

output
YES
0

input
111111

output
NO

这道题我是找规律的,首先我发现后两位数是有重复的,比如说从0~100与200~300的后两位是重复的,从100~200与300~400的后两位是重复的,所以我们可以对后两位进行判断。

代码有点挫,先贴上来,明天再整理下。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxn 111
char a[maxn];
int mp[33];
int main(){scanf("%s",a);int len=strlen(a);for(int i=0;i<len;i++){mp[a[i]-'0']++;}if(mp[0]||mp[8]){puts("YES");if(mp[0]) {printf("0\n"); return 0;}if(mp[8]) {printf("8\n"); return 0;}}else{if(!mp[2]&&!mp[4]&&!mp[6]) puts("NO");else{if(mp[2]){bool ff=false;int tx=0;int ss1,ss2[maxn]={0},ii=0,pos=0;for(int i=0;i<len;i++){if(a[i]-'0'==3) {ss1=i; break;}}for(int i=0;i<len;i++){if(a[i]-'0'==2) ss2[ii++]=i;}for(int i=0;i<len;i++){if((a[i]-'0')%2) {tx=a[i]-'0'; pos=i; ff=true; break;}}bool flag=false;for(int i=0;i<ii;i++){if(ss1<ss2[i])  {flag=true; break;}}if(mp[3]&&flag) {puts("YES"); printf("32\n");return 0;}for(int i=0;i<len;i++){if(a[i]-'0'==7) {ss1=i; break;}}flag=false;for(int i=0;i<ii;i++){if(ss1<ss2[i])  {flag=true; break;}}if(mp[7]&&flag) {puts("YES"); printf("72\n");return 0;}int nn=0,ss3=0;for(int i=0;i<len;i++){if(a[i]-'0'==1&&nn==0) {ss1=i; nn++;}if(a[i]-'0'==1&&nn==1) {ss3=i,nn++;break;}}flag=false;for(int i=0;i<ii;i++){if(ss1<ss2[i]&&ss3<ss2[i])  {flag=true; break;}}if(mp[1]>=2&&flag) {puts("YES"); printf("112\n");return 0;}for(int i=0;i<len;i++){if(a[i]-'0'==5) {ss1=i; break;}}flag=false;for(int i=0;i<ii;i++){if(ss1<ss2[i]&&pos<ss2[i]&&pos<ss1)  {flag=true; break;}}if(ff&&mp[5]&&flag) {puts("YES"); printf("%d52\n",tx);return 0;}for(int i=0;i<len;i++){if(a[i]-'0'==9) {ss1=i; break;}}flag=false;for(int i=0;i<ii;i++){if(ss1<ss2[i]&&pos<ss2[i]&&pos<ss1)  {flag=true; break;}}if(ff&&mp[9]&&flag) {puts("YES"); printf("%d92\n",tx);return 0;}}if(mp[4]){bool ff=false,flag=false;int tx=0,pos=0;int ss1,ss2[maxn]={0},ii=0;for(int i=0;i<len;i++){if(a[i]-'0'==4) ss2[ii++]=i;}for(int i=0;i<len;i++){if((a[i]-'0')%2) {tx=a[i]-'0'; pos=i; ff=true; break;}}for(int i=0;i<len;i++){if(a[i]-'0'==2) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]) {flag=true; break;}}if(mp[2]&&flag) {puts("YES"); printf("24\n");return 0;}flag=false;for(int i=0;i<len;i++){if(a[i]-'0'==6) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]) {flag=true; break;}}if(mp[6]&&flag) {puts("YES"); printf("64\n");return 0;}flag=false;for(int i=0;i<ii;i++){if(pos<ss2[i]) {flag=true; break;}}if(ff&&mp[4]>=2&&flag) {puts("YES"); printf("%d44\n",tx);return 0;}flag=false;for(int i=0;i<len;i++){if(a[i]-'0'==8) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]&&pos<ss2[i]&&pos<ss1) {flag=true; break;}}if(ff&&mp[8]&&flag) {puts("YES"); printf("%d84\n",tx);return 0;}}if(mp[6]){bool ff=false,flag=false;int tx=0,pos=0;int ss1,ss2[maxn]={0},ii=0;for(int i=0;i<len;i++){if(a[i]-'0'==6) ss2[ii++]=i;}for(int i=0;i<len;i++){if((a[i]-'0')%2) {tx=a[i]-'0'; pos=i; ff=true; break;}}for(int i=0;i<len;i++){if(a[i]-'0'==1) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]) {flag=true; break;}}if(mp[1]&&flag) {puts("YES"); printf("16\n");return 0;}flag=false;for(int i=0;i<len;i++){if(a[i]-'0'==5) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]) {flag=true; break;}}if(mp[5]&&flag) {puts("YES"); printf("56\n");return 0;}flag=false;for(int i=0;i<len;i++){if(a[i]-'0'==9) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]) {flag=true; break;}}if(mp[9]&&flag) {puts("YES"); printf("96\n");return 0;}for(int i=0;i<len;i++){if(a[i]-'0'==3) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]&&pos<ss2[i]&&pos<ss1) {flag=true; break;}}if(ff&&mp[3]&&flag) {puts("YES"); printf("%d36\n",tx);return 0;}flag=false;for(int i=0;i<len;i++){if(a[i]-'0'==7) {ss1=i; break;}}for(int i=0;i<ii;i++){if(ss1<ss2[i]&&pos<ss2[i]&&pos<ss1) {flag=true; break;}}if(ff&&mp[7]&&flag) {puts("YES"); printf("%d76\n",tx);return 0;}}puts("NO");}}return 0;
}

感觉就像是一个暴暴力~~~

还有每次必说的——加油!

Codeforces Round #306 (Div. 2)相关推荐

  1. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  2. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  3. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  4. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  5. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  6. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  7. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  8. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  9. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

  10. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

最新文章

  1. Python之IO编程
  2. 解秘亿级网站的一本书——亿级流量网站架构核心技术
  3. 「递归」第9集 | 我在腾讯做研究
  4. 开场 Live,分享点干货——「深入了解 Node.js 包与模块机制」
  5. 孩子大了真是不好管了
  6. MySQL把多条数据给汇总成一条数据
  7. [Alamofire] 错误总结
  8. win7 远程桌面 复制粘贴
  9. (56)Verilog HDL双向接口:inout
  10. php读入输入_php-读取用户输入并检查数据类型
  11. JAVA SSH框架的配置(myeclipse(9)+tomcat(6.0.35)+struts(2.2.3)+Spring(3.0)+Hibernate(3.0))
  12. 挖掘11亿用户背后的产品逻辑之美
  13. php asp网站本地调试,php/asp网站程序本地调试工具
  14. dump文件 linux,Linux下快速分析DUMP文件
  15. android RS485串口接线正反的问题
  16. 最小二乘法求回归直线方程的推导过程
  17. linux安装xbox无线手柄,win10系统如何连接xbox360无线手柄
  18. Google CFO 的辞职信(引用)
  19. winsxs是什么文件夹 Winsxs文件夹可以删除吗
  20. Pytorch 多线程 运行卡死

热门文章

  1. css旋转立方体教程,如何通过CSS3实现旋转立方体
  2. 回文数字 观察数字:12321,123321都有一个共同的特征,无论从左到右读还是从右向左读;都是相同的。这样的数字叫做: 回文数字。 本题要求你找到一些5位或6位的十进制数字。满足要求: 该数字
  3. 阿里云商标注册查询系统入口链接(支持图片搜索)
  4. 水星怎么设置网速最快_水星怎么设置路由器的网速
  5. SageMath密码学密码体制及加解密
  6. 全球高效能人士给青年的50个忠告(上) --转载
  7. iOS开发中使用代码控制横竖屏的切换
  8. 当孙子兵法遇上词云,会有怎样的碰撞?
  9. mysql根据身份证号计算年龄
  10. qt4谷歌输入法 linux,linux mint设置google pinyin输入法