Codeforces Round #429
Table of Contents A. Generous KefaB. GodsendC. Leha and Function
A. Generous Kefa
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s**i — 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».
题意:将气球全部发给一些人,每个人不能收到相同颜色的气球,是否可以将气球全部发出去。
#include <bits/stdc++.h>
using namespace std;
char str[105];
int num[30];
int main(int argc, char const *argv[])
{
int n,k;
scanf("%d%d",&n,&k);
scanf("%s",str);
for(int i=0;i<n;i++)
num[str[i]-'a']++;
bool flag = true;
for(int i=0;i <26;i++) {
if(num[i]>k) {
flag = false;
break;
}
}
if(flag)
puts("YES");
else puts("NO");
return 0;
}
B. Godsend
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.
题意:博弈,给一个数列,第一个人先手,每次选取一个奇数区间拿走,第二个后手,每次选取一个偶数区间拿走,谁不能动,谁输。
分析:数据量很大,而且不能区间求和,说明这和奇偶相关。
当整个区间为奇数时,先手全部拿走。
当整个区间有奇数个奇数(先手全部拿走)。
当整个区间有偶数个奇数(先手拿的只剩下一个奇数。后手却只能拿不走那个奇数,先手第二次全部拿走)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
int a[maxn];
int main(int argc, char const *argv[])
{
int n;
cin>>n;
long long sum = 0;
int u;
int cnt1,cnt2;
cnt1 = cnt2 = 0;
for(int i=0; i < n; i++) {
scanf("%d",&u);
a[i] = u%2;
sum+=a[i];
if(a[i]%2) cnt1++;
else cnt2++;
}
if(sum%2)
puts("First");
else {
if(cnt1>0)
puts("First");
else puts("Second");
}
return 0;
}
C. Leha and Function
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 m integers. 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
题意:
F(n,k) 函数,从 1~n 个数中,挑取 k 个数,然后取这个集合中最小的值,F(n,k),就是这个最小值的期望。
推导,F(n,k)=\frac{n+1}{k+1} 没仔细去推。
然后,\sum_{i=1}^mF(A_i',B_i) 最大时,A数组重排。
贪心,A中最大的元素匹配B中最小的元素。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
struct node {
int x;
int id;
}a[maxn],b[maxn];
bool cmp(node a,node b) {
return a.x < b.x;
}
bool cmp2(node a,node b) {
return a.x > b.x;
}
bool cmp3(node a,node b) {
return a.id < b.id;
}
int main() {
int m;
scanf("%d",&m);
for(int i=0; i < m; i++) {
scanf("%d",&a[i].x);
a[i].id = i;
}
for(int i=0; i < m; i++) {
scanf("%d",&b[i].x);
b[i].id = i;
}
sort(a,a+m,cmp2);
sort(b,b+m,cmp);
for(int i=0; i < m; i++)
a[i].id = b[i].id;
sort(a,a+m,cmp3);
for(int i=0; i < m; i++)
printf("%d ",a[i].x);
return 0;
}
Codeforces Round #429的更多相关文章
- CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)
思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组, ...
- CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上 ...
- CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...
- codeforces Round#429 (Div2)
2017-08-20 10:00:37 writer:pprp 用头文件#include <bits/stdc++.h>很方便 A. Generous Kefa codeforces 84 ...
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...
- Codeforces Round #429 (Div. 2/Div. 1) [ A/_. Generous Kefa ] [ B/_. Godsend ] [ C/A. Leha and Function ] [ D/B. Leha and another game about graph ] [ E/C. On the Bench ] [ _/D. Destiny ]
PROBLEM A/_ - Generous Kefa 题 OvO http://codeforces.com/contest/841/problem/A cf 841a 解 只要不存在某个字母,它的 ...
- 【Codeforces Round #429 (Div. 2) C】Leha and Function
[Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...
- 【Codeforces Round #429 (Div. 2) B】 Godsend
[Link]:http://codeforces.com/contest/841/problem/B [Description] 两个人轮流对一个数组玩游戏,第一个人可以把连续的一段为奇数的拿走,第二 ...
- Codeforces Round #429 (Div. 2) 补题
A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...
- Codeforces Round #429 Div. 1
A:甚至连题面都不用仔细看,看一下样例就知道是要把大的和小的配对了. #include<iostream> #include<cstdio> #include<cmath ...
随机推荐
- Jmeter4.0----HTTP Cookie管理器(9)
1.说明 在脚本编写的过程中,我们常常会遇到用户登录之后的相关操作,但是又不想去通过脚本先模拟用户登录,再使用cookie值保持登录,做后续的操作的情况下,我们就会用到HTTP Cookie管理. H ...
- 字符型图片验证码,使用tensorflow实现卷积神经网络,进行验证码识别CNN
本项目使用卷积神经网络识别字符型图片验证码,其基于 TensorFlow 框架.它封装了非常通用的校验.训练.验证.识别和调用 API,极大地减低了识别字符型验证码花费的时间和精力. 项目地址: ht ...
- mysql explain工具使用
explain工具可以确认执行计划是否良好,查询是否走了合理的索引.查询的执行计划,随着数据的变化也可能会有变化.调用方式:explain + [sql语句]. 另外,explain是有局限性的:1. ...
- mysql - VARCHAR与VHAR的区别
一, 基本介绍 char 和 varchar 两类型类似, 用来存储字符串,不同之处来自于他们的保存和检索的差别, char 属于固定的长度字符类型, 而varchar 属于可变长度的字符类型 值 C ...
- windows 系统 python3.5安装 lxml 库
有个提示uable find vc***,的错误,如果按照修改python脚本的方法会发现还需要安装VS,安装好了还不一定可以解决问题. 费了半天劲,结合网络上部分信息终于找到了解决方案: 1.打开文 ...
- 转-------基于R-CNN的物体检测
基于R-CNN的物体检测 原文地址:http://blog.csdn.net/hjimce/article/details/50187029 作者:hjimce 一.相关理论 本篇博文主要讲解2014 ...
- linux_api之进程环境
本篇索引: 1.引言 2.main函数 3.进程的终止方式 4.exit和_exit函数 5.atexit函数 7.环境表 8.C程序程序空间布局 9.存储空间的手动分配 10.库文件 1.引言 一个 ...
- php获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime.下面首先还是直奔主题以示例说明如何使用 mktime 获取今日.昨日.上周.本月的起始 ...
- netstat参数
1.功能与说明 netstat 用于显示linux中各种网络相关信息.如网络链接.路由表.接口状态链接.多播成员等等. 定义:Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TC ...
- jQuery前端数据通用验证库,解放你的双手
这个简易的验证库,应该能完成90%的基本验证,包括失去焦点时的验证,以及点击提交按钮时的验证.后端的那我就无能为办了,只能是谁用就谁自个儿去写了:). 先上一段调用的代码吧,JS代码说少也不少了,就不 ...