Codeforces Round #442 (Div. 2) ABC

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

给定一串字符串 ,出现了给定的五个名字中的一次就是YES,否则是NO。
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char str[110];
 4 int main() {
 5     cin >> str;
 6     int ans = 0;
 7     for(int i = 0; str[i]; i ++) {
 8         if(str[i] == 'D') {
 9             if(str[i+1] == 'a' && str[i+2] == 'n' && str[i+3] == 'i' && str[i+4] == 'l') {
10                 ans ++;
11                 i+= 4;
12             }
13         }
14         if(str[i] == 'O') {
15             if(str[i+1] == 'l' && str[i+2] == 'y' && str[i+3] == 'a') {
16                 ans ++;
17                 i += 3;
18             }
19         }
20         if(str[i] == 'S') {
21             if(str[i+1] == 'l' &&str[i+2] == 'a' && str[i+3] == 'v' && str[i+4] == 'a') {
22                 ans ++;
23                 i += 4;
24             }
25         }
26         if(str[i] == 'A') {
27             if(str[i+1] == 'n' && str[i+2] == 'n') {
28                 ans ++;
29                 i += 2;
30             }
31         }
32         if(str[i] == 'N') {
33             if(str[i+1] == 'i' && str[i+2] == 'k' && str[i+3] == 'i' && str[i+4] == 't' && str[i+5] == 'a') {
34                 ans ++;
35                 i += 5;
36             }
37         }
38     }
39     if(ans == 1) printf("YES\n");
40     else printf("NO\n");
41     return 0;    
42 }
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.

看到网上一种思路,挺好的。

主要是分解成a   ab/ba   aba这三种

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N = 5010;
 4 char str[N];
 5 int dp[3][N];
 6 int main() {
 7     cin >> str;
 8     int len = strlen(str);
 9     for(int i = 0; i < len; i ++) {
10         dp[0][i+1] = dp[0][i] + (str[i] == 'a');
11         dp[1][i+1] = max(dp[0][i], dp[1][i]) + (str[i] == 'b');
12         dp[2][i+1] = max(max(dp[0][i],dp[1][i]),dp[2][i]) + (str[i] == 'a');
13     }
14     printf("%d\n",max(dp[0][len], max(dp[1][len],dp[2][len])));
15     return 0;
16 }
C. Slava and tanks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.

Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.

If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the cell n - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.

Help Slava to destroy all tanks using as few bombs as possible.

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

Output

In the first line print m — the minimum number of bombs Slava needs to destroy all tanks.

In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki.

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

Examples
input
2
output
3
2 1 2
input
3
output
4
2 1 3 2

思维题,n之内的奇数会大于等于偶数,所以答案就是偶数-奇数-偶数。
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     int n;
 6     cin >> n;
 7     printf("%d\n",n/2*3+((n&1)?1:0));
 8     for(int i = 2; i <= n; i += 2) printf("%d ",i);
 9     for(int i = 1; i <= n; i += 2) printf("%d ",i);
10     for(int i = 2; i <= n; i += 2) printf("%d ",i);
11     printf("\n");
12     return 0;
13 }

 

posted @ 2017-10-30 14:58  starry_sky  阅读(244)  评论(0编辑  收藏  举报