Codeforces Round #442 (Div. 2) A. Alex and broken contest,B
来源:互联网 发布:加内特2008季后赛数据 编辑:程序博客网 时间:2024/06/05 02:10
A. Alex and broken contest
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex’s friends’ name exactly once. His friends’ names are “Danil”, “Olya”, “Slava”, “Ann” and “Nikita”.
Names are case sensitive.
Input
The only line contains string from lowercase and uppercase letters and “_” symbols of length, not more than 100 — the name of the problem.
Output
Print “YES”, if problem is from this contest, and “NO” otherwise.
Examples
input
Alex_and_broken_contest
output
NO
input
NikitaAndString
output
YES
input
Danil_and_Olya
output
NO
translation :
那几个名字所有出现过的次数为1输出YES 否则NO;
解 模拟;
#include<string>#include<iostream>#include<cstdio>using namespace std;int main(){ string s; while (cin>>s) { int sum = 0; int t = s.find("Danil"); if (t != string::npos) { sum++; if (s.find("Danil",t+1) != string::npos) sum++; } t = s.find("Olya"); if (t != string::npos) { sum++; if (s.find("Olya", t + 1) != string::npos) sum++; } t = s.find("Slava"); if (t != string::npos) { sum++; if (s.find("Slava", t + 1) != string::npos) sum++; } t = s.find("Ann"); if (t != string::npos) { sum++; if (s.find("Ann", t + 1) != string::npos) sum++; } t = s.find("Nikita"); if (t != string::npos) { sum++; if (s.find("Nikita", t + 1) != string::npos) sum++; } // cout << sum << endl; if (sum == 1) puts("YES"); else puts("NO"); } return 0;}
B. Nikita and string
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Nikita found the string containing letters “a” and “b” only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters “a” and the 2-nd contains only letters “b”.
Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
Input
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters “a” and “b”.
Output
Print a single integer — the maximum possible size of beautiful string Nikita can get.
Examples
input
abba
output
4
input
bab
output
2
Note
It the first sample the string is already beautiful.
In the second sample he needs to delete one of “b” to make it beautiful.
translation;
给你只有a ,b的串,将串分为3部分,可以为空,第一,第三部分只能由’a’组成,中间的只能为’b’,可以删除任意字节,求解最大长度;
ans
情况分为 a ,ab, ba, aba, ba可以忽略因为 如果前面有a是一定要加上,所以还是aba的情况;
#include<bits/stdc++.h>using namespace std;int main(){ char s[5555]; while(cin>>s) { int dp[3][5001]={0},i,j; int len=strlen(s); for(i=0;i<len;i++) { dp[0][i+1]=dp[0][i]+(s[i]=='a'); dp[1][i+1]=max(dp[0][i],dp[1][i])+(s[i]=='b'); dp[2][i+1]=max(max(dp[0][i],dp[1][i]),dp[2][i])+(s[i]=='a'); } cout<<max(max(dp[0][len],dp[1][len]),dp[2][len])<<endl; } return 0;}
- Codeforces Round #442 (Div. 2) A. Alex and broken contest
- Codeforces Round #442 (Div. 2) A Alex and broken contest
- Codeforces Round #442 (Div. 2) A. Alex and broken contest
- Codeforces Round #442 (Div. 2) A. Alex and broken contest,B
- Alex and broken contest Codeforces Round #442
- Codeforces 877 A Alex and broken contest
- codeforces 442 A. Alex and broken contest(水题)
- A. Alex and broken contest
- A. Alex and broken contest
- Codeforces Round #216 (Div. 2) B. Valera and Contest
- Codeforces Round #216 (Div. 2) B. Valera and Contest
- [水题]Codeforces Round #307 (Div. 2) A.GukiZ and Contest
- Codeforces Round #307 (Div. 2) A. GukiZ and Contest
- CF#877 A. Alex and broken contest(KMP)
- Codeforces Round #267 (Div. 2) E Alex and Complicated Task
- Codeforces Round #442 (Div. 2) A B
- Codeforces Round #187 (Div. 2) A and B
- Codeforces Round #178 (Div. 2) A and B
- 用Margin还是用Padding
- Docker 支持原生 Kubernetes,Docker Swarm 失败了?
- 周末读书|《大众天文学》:少年,追星吗?
- 前端组件开发大赛,约吗?
- Tensorflow GPU 源码安装configure 配置
- Codeforces Round #442 (Div. 2) A. Alex and broken contest,B
- java 中判断字符串是否为空的几种操作
- Android apk签名 Structure配置与Gradle的关係
- Odps(MaxCompute)使用时一些问题
- 单链表的创建、打印完整程序
- Spring Cloud Zuul实现动态路由(zuul设计)
- Access denied for user 'root'@'localhost' (using password: YES)
- 写给小白的android Handler机制详解
- Integer Break