Codeforces Round #442 (Div. 2)

A. Alex and broken contest
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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

题意  是否所有名字中只出现一次

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = ;
typedef long long ll;
string a;
string b[]={"Danil","Olya","Slava","Ann","Nikita"};
int main()
{
cin>>a;
int sum=;
for(int i=;i<;i++)
{
if(a.find(b[i])!=-) //find找到子串第一次出现的位置返回下标
sum++;
if(a.rfind(b[i])!=a.find(b[i])) //rfind找到子串最后一次出现的位置返回下标
sum++;
}
if(sum>||sum==)
printf("NO\n");
else
printf("YES\n");
return ;
}
B. Nikita and string
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

解析  前缀和暴力枚举所有划分

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int a[maxn],b[maxn];
char s[maxn];
int main()
{
while(scanf("%s",s)!=EOF)
{
int len=strlen(s);
a[]=b[]=;
for(int i=;i<len;i++) //一共 len 位 0~len-1
{
a[i+]=a[i]; //a[i]表示第i位之前 不包括第i位 有多少个a
b[i+]=b[i]; //b[i]表示第i位之前 不包括第i位 有多少个b
if(s[i]=='a')
a[i+]++;
else
b[i+]++;
}
int maxx=;
for(int i=;i<=len;i++) //将 len-1位 划分为成 三个区间[1,i-1],[i,j-1],[j,len-1],枚举划分情况
{
for(int j=i;j<=len;j++)
{
int now=a[i]+(b[j]-b[i])+(a[len]-a[j]); //当前情况的长度 a + b + a
maxx=max(maxx,now); //更新最优值
}
}
printf("%d\n",maxx);
}
}

C题  偶奇偶 来炸就好了 一共n+n/2次

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = ;
typedef long long ll;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int ans=n+n/;
printf("%d\n",ans);
for(int i=;i<=n;i++)
{
if(i%==)
printf("%d ",i);
}
for(int i=;i<=n;i++)
{
if(i%==)
printf("%d ",i);
}
for(int i=;i<=n;i++)
{
if(i%==)
{
if(i+>n)
printf("%d\n",i);
else
printf("%d ",i);
}
}
}
return ;
}
上一篇:ArcGIS Engine 连接SQL Server并建立关联


下一篇:Java异常及异常块执行次序(try、catch、finally、return)