Codeforces Round #429 (Div. 2)
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.
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.
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
题意: 让你分配东西,然后每个人不能分配相同的东西 就是看看东西的种类 和 总人数的比较
#include<bits/stdc++.h>
using namespace std;
int p[];
char s[];
int main ()
{
int n,k;
cin >> n >>k;
int sum=,ans=;
for(int i=;i<n;i++)
{
cin>>s[i];
if(!p[s[i]])
sum++;
p[s[i]]++;
ans = max(ans,p[s[i]]);
}
if(ans <= k)
puts("YES");
else
puts("NO");
}
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?
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 answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
题意:这个题 比较绕脑子,就是A可以挑一串连续的 和为奇数的子串
B再挑和为偶数数的子串
其实 : 看过样例,多想想就会明白 如果这个串是奇数的话,那么 A一下子拿走 A就赢了
如果串是偶数的话,那么 分两种情况 因为奇数+奇数==偶数 偶数+偶数==偶数
考虑如果整个串都是偶数的话,那么必然 A不能拿 B能拿 B就赢了
如果不是的话 肯定是A要取奇数 B再取偶数 然后A在取奇数 然后A就赢了
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+;
typedef long long ll;
int s[maxn];
ll sum[maxn]; int main ()
{
int n;
cin >> n;
for(int i=;i<=n;i++){
cin>>s[i];
sum[i] =s[i]+sum[i-];
}
if(sum[n]&)
{
cout<<"First"<<endl;
return ;
}
else
{
int ans = ;
for(int i=;i<=n;i++)
if(sum[i]%==)
{
ans++;
}
if(ans == n)
{
cout<<"Second"<<endl;
}
else
{
cout<<"First"<<endl;
}
}
}
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.
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 m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.
题意 : 大概就是感觉 直接找B中最小的 和 A中最大的这样子
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+; int n;
struct p
{
int x;
int pos; }a[maxn],b[maxn]; int t[maxn];
bool cmp(p a,p b)
{
return a.x>b.x;
}
bool cmp1(p a,p b)
{
return a.x < b.x;
}
bool cmp2(p a,p b)
{
return a.pos < b.pos;
}
int main ()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++)
cin>>a[i].x;
for(int i=;i<=n;i++){
cin>>b[i].x;
b[i].pos = i;
}
sort(a+,a+n+,cmp);//a从大到小已经排好
sort(b+,b+n+,cmp1);//b从小到大排序
for(int i=;i<=n;i++)
{
a[i].pos = b[i].pos;
}
sort(a+,a+n+,cmp2);
for(int i=;i<=n;i++)
{
if(i==)
cout<<a[i].x;
else
cout<<" "<<a[i].x;
}
cout<<endl; }
第一次能做出来三道题 有点儿小激动...虽然还是很菜,继续坚持就好
Codeforces Round #429 (Div. 2)的更多相关文章
- 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 (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 ...
- Codeforces Round #429 (Div. 1) C. On the Bench(dp + 组合数)
题意 一个长度为 \(n\) 的序列 \(A\) ,定义一个 \(1\) 到 \(n\) 的排列 \(p\) 是合法的,当且仅当 \(\forall i \in [1, n − 1], A_{p_i} ...
随机推荐
- (1.3)mysql 事务控制和锁定语句
(1.3)mysql 事务控制和锁定语句 lock table 参考转载自:https://www.cnblogs.com/kerrycode/p/6991502.html 关键词:mysql loc ...
- 如何让dedecms文章点击量增加一定的数值
用dedecms建站都知道有一个文章点击量这个参数,我们可不可以用这个浏览量做些延伸扩展呢?比如加上一个固定值变成另外一个指标.很多朋友已经想到了,如下图,我们将本文浏览量286设为点击量,加上300 ...
- 梯度下降算法(Gradient Descent)
近期在搞论文,须要用梯度下降算法求解,所以又一次整理分享在这里. 主要包含梯度介绍.公式求导.学习速率选择.代码实现. 梯度下降的性质: 1.求得的解和选取的初始点有关 2.能够保证找到局部最优解,由 ...
- layer,一个可以让你想到即可做到的javascript弹窗(层)解决方案
学习网址:http://layer.layui.com/ 下载地址:http://res.layui.com/download/layer-v2.1.zip 我们提到的基础参数主要指调用方法时用到的配 ...
- spring boot上传 下载图片。
https://blog.csdn.net/a625013/article/details/52414470 build.gradle buildscript { repositories { mav ...
- hiredis(Synchronous API)
hiredis是一个小型的client端的c库.它只增加了最小对协议的支持,同时它用一个高级别的printf-alike API为了绑定各种redis命令.除了支持发送和接收命令,它还支持对流的解析. ...
- How to enable TLS 1.2 on Windows Server 2008 R2
Problem How to enable TLS 1.2 on Windows Server 2008 R2? Resolution QuoVadis recommends enabling and ...
- X-Forwarded-For 负载均衡 7 层 HTTP 模式获取来访客户端真实 IP 的方法(IIS/Apache/Nginx/Tomcat)
https://help.aliyun.com/knowledge_detail/13051859.html?pos=1 1.IIS 6 配置方案2.IIS 7 配置方案3.Apache 配置方案4. ...
- EF5.0区别于EF4.0的增删改写法
// 实现对数据库的添加功能,添加实现EF框架的引用 public T AddEntity(T entity) { //EF4.0的写法 添加实体 //db.CreateObjectSet<T& ...
- 服务器修改用户密码注意iis部署的网站问题
当服务器修改用户密码时,需要修改iis上部署的跟此用户权限有关的所有网站,选择网站——右击——应用程序管理——高级设置——物理路径凭证——特定用户——修改用户名和密码.