A. Generous Kefa
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
One 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.
Input
The 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.
Output
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Examples
input
4 2
aabb
output
YES
input
6 3
aacaab
output
NO
Note
In 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».
题意:有n个气球,每个气球颜色是可以相同的,这人有k个朋友,他打算把n个气球全部发给这k个人,但是每个人收到的每个气球颜色都不相同,下面用小写字符a-z表示不同颜色的气球,问能不能分给他的朋友
思路:一共有k个朋友,每个朋友手里的气球颜色都不同,所只需要记录每个颜色气球的个数即可,如果存在某种颜色的气球个数大于k就输出NO,否则都是YES
代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int n,m;
char a[110];
int num[110];
int main()
{
while(~scanf("%d%d",&n,&m))
{
scanf("%s",a);
memset(num,0,sizeof(num));
for(int i=0; a[i]; i++)
num[a[i]-'a']++;
int flag=0;
for(int i=0; i<26; i++)
{
if(num[i]>m)
{
flag=1;
break;
}
}
if(flag)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
B. Godsend
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Leha 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?
Input
First 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).
Output
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
Examples
input
4
1 3 2 3
output
First
input
2
2 2
output
Second
Note
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
题意:给你一个数组,这里有两个人,第一个人只能拿这个数组的一个和为奇数的子数组,第二个人只能拿这个数组的一个和为偶数的子数组,若轮到第一个人拿的时候刚好拿完就第一个人赢,输出Frist ;否则第二个人赢,输出Second。
思路:仔细想了一下,只需要这个数组存在奇数就是第一个人赢,如果就只有一个奇数那第一个人只需要第一次就拿完,如果有两个奇数,那第一个人只需要留一个奇数给第二个人拿,但是第二个人不能拿奇数最后还是第一人赢,如果有三个及以上的奇数个数那么拿法还是跟有两个奇数一样。
代码:
#include<stdio.h>
#include<string.h>
#define ll long long
using namespace std;
int n;
ll a[1000006];
int main()
{
while(~scanf("%d",&n))
{
int cnt=0;
for(int i=0; i<n; i++)
{
scanf("%lld",&a[i]);
if(a[i]&1)
cnt++;
}
if(cnt>=1)
printf("First\n");
else
printf("Second\n");
}
return 0;
}
C. Leha and Function
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets.
But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays A and B, each consists of mintegers. For all i, j such that 1 ≤ i, j ≤ m the condition Ai ≥ Bj holds. Help Leha rearrange the numbers in the array A so that the sum is maximally possible, where A' is already rearranged array.
Input
First line of input data contains single integer m (1 ≤ m ≤ 2·105) — length of arrays A and B.
Next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 109) — array A.
Next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109) — array B.
Output
Output m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.
Examples
input
5
7 3 5 3 4
2 1 3 2 3
output
4 7 3 5 3
input
7
4 6 5 8 8 2 6
2 1 2 2 1 1 2
output
2 6 4 5 8 8 6
题意:给你个变化后的A串(A‘),在给你B串,函数F(n,k)的功能是求0~n的集合中找一个长度为k的最小元素和,如果(n>k)那么F(n,k)=(k+1)*k/2;否则F(n,k)=(1+n)*n/2;
现在已知A’数组和B数组,求出F(A',B)的值为最小时A数组对应是什么?
思路:看样例一:
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
int n;
ll a[200010];
struct node
{
ll x,id;
} b[200010];
ll c[200010];
bool cmp(node aa,node bb)
{
return aa.x>bb.x;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
scanf("%lld",&a[i]);
for(int i=0; i<n; i++)
{
scanf("%lld",&b[i].x);
b[i].id=i;
}
sort(a,a+n);
sort(b,b+n,cmp);
for(int i=0; i<n; i++)
c[b[i].id]=a[i];
for(int i=0; i<n; i++)
i==n-1?printf("%d\n",c[i]):printf("%d ",c[i]);
}
return 0;
}