Codeforces Round #429 (Div. 2)
A. Generous Kefatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
InputThe first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
OutputAnswer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examplesinput4 2
aabboutputYESinput6 3
aacaaboutputNONoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
思路:重复的气球的个数如果超过人数就NO。
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 int flag[200]; 7 int main(){ 8 int n,k; 9 cin>>n>>k; 10 char a[105]; 11 memset(flag,0,sizeof(flag)); 12 cin>>a; 13 int mx=0; 14 for(int i=0;i<strlen(a);i++){ 15 flag[a[i]]++; 16 if(mx<flag[a[i]]){ 17 mx=flag[a[i]]; 18 } 19 } 20 if(mx>k) cout<<"NO"<<endl; 21 else cout<<"YES"<<endl; 22 return 0; 23 }
B. Godsendtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLeha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
InputFirst line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
OutputOutput answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
Examplesinput4
1 3 2 3outputFirstinput2
2 2outputSecondNoteIn first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
题目大意:两人玩游戏,第一个人取和为奇数的区间,第二个取和为偶数的区间。直到某人无法操作,某人输。
思路:只要判断整个数组是否有奇数,如果没有奇数,那么second赢,否则first赢。(ps:如果数组和为奇数,那么一次就赢了,如果是偶数,且存在奇数,那么往后必定first赢,因为操作最优,只有当不存在奇数,first无法操作就second 赢)
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #include<string.h> 5 using namespace std; 6 int main(){ 7 int n; 8 cin>>n; 9 int tmp; 10 int flag=0; 11 long long int sum=0; 12 for(int i=0;i<n;i++){ 13 scanf("%d",&tmp); 14 sum+=tmp; 15 if(tmp%2==1) flag=1; 16 } 17 if(sum%2==1){ 18 cout<<"First"<<endl; 19 return 0; 20 } 21 if(sum%2==0&&flag==0){ 22 cout<<"Second"<<endl; 23 return 0; 24 } 25 cout<<"First"<<endl; 26 return 0; 27 }