Codefroces Round #429Div2 (A,B,C)
2 seconds
256 megabytes
standard input
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.
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.
4 2
aabb
YES
6 3
aacaab
NO
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».
注意题目被标记部分;分不到不会沮丧,分不完会沮丧,所以,某个颜色大于K时就输出NO
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a[],n,k;
char s[];
int main()
{
cin>>n>>k;
int flag=true;
memset(a,,sizeof(a));
cin>>s;
for(int i=;s[i]!='\0';i++)
a[s[i]-'a']++;
for(int i=;i<;i++)
{
if(a[i]>k) flag=;
}
puts(flag?"YES":"NO");
return ;
}
2 seconds
256 megabytes
standard input
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?
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).
4
1 3 2 3
First
2
2 2
Second
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.
首先,全为偶数时,后手一定赢,偶数加奇数=奇数,偶数加偶数=偶数,所以奇数可以表示为=奇书+n*偶数(即和偶数数目无关),有一个奇数时,先手一次性全拿走,两个时,分两次拿,所以无论哪种情况,有奇数个奇数时,全拿走,偶数个奇数时分两次拿,所以只要存在奇数先手一定赢。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
int pos=,n,x;
scanf("%d",&n);
while(n--)(scanf("%d",&x),x%?pos++:);
puts(pos?"First":"Second");
}
2 seconds
256 megabytes
standard input
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 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.
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.
5
7 3 5 3 4
2 1 3 2 3
4 7 3 5 3
7
4 6 5 8 8 2 6
2 1 2 2 1 1 2
2 6 4 5 8 8 6
任意子集尽可能大,所以排序后,小得对应大的,大的尽可能排到前面
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a[],vis[],n;
pair<int,int>p[];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<n;i++)
{
scanf("%d",&p[i].first);
p[i].second=i;
}
sort(a,a+n);
sort(p,p+n);
for(int i=;i<n;i++)
{
vis[p[i].second]=a[n-i-];
}
for(int i=;i<n;i++)
{
if(i) printf(" ");
printf("%d",vis[i]);
}
printf("\n");
return ;
}
Codefroces Round #429Div2 (A,B,C)的更多相关文章
- Codefroces Round#427 div2
A. Key races time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codefroces Round #201.B--Fixed Points
B. Fixed Points time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codefroces Round #201.a--Difference Row
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description You wa ...
- Codefroces Educational Round 26 837 D. Round Subset
D. Round Subset time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codefroces Educational Round 27 845G Shortest Path Problem?
Shortest Path Problem? You are given an undirected graph with weighted edges. The length of some pat ...
- Codefroces Educational Round 27 (A,B,C,D)
A. Chess Tourney time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codefroces Educational Round 26 837 B. Flag of Berland
B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codefroces Educational Round 26 837 C. Two Seals
C. Two Seals time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等
在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...
随机推荐
- 设置cookie的方法
设置cookie的方法 1.登录之后后端返回的cookie放在响应的数据里,我们可以取到值, 这样就设置上了一个cookie,然后由于我们需要在三个环境里进行操作,开发环境.测试环境.生产环境.刚刚上 ...
- 洛谷1005 【NOIP2007】矩阵取数游戏
问题描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...
- [笔记-图论]Dijkstra
用于求正权有向图 上的 单源最短路 优化后时间复杂度O(mlogn) 模板 // Dijkstra // to get the minumum distance with no negtive way ...
- ECNUOJ 2616 游黄山
游黄山 Time Limit:1000MS Memory Limit:65536KB Total Submit:165 Accepted:52 Special Judge Description Po ...
- MongoDB 基本使用
数据库基本操作 连接到mongoDBserver 1 ./bin/mongo 127.0.0.1:12345 查看当前数据库 1 2 3 > show dbs admin (empty) ...
- Word 操作组件介绍 - Spire.Doc
http://www.cnblogs.com/liqingwen/p/5898368.html
- OpenCV与Socket实现树莓派获取摄像头视频至电脑
OpenCV能够为我们带来便捷的图像处理接口,但是其处理速度在一块树莓派上肯定是不尽如人意的.尤其当我们想要使用复杂的算法时,只能把算法托到服务器上才有可能.这里介绍了一种方法,实现树莓派传输Mat至 ...
- 《读书报告 – Elasticsearch入门 》----Part II 深入搜索(2)
第十三章 全文检索 这一章开始介绍 全文检索 :怎样对全文字段(full-text fields)进行检索以找到相关度最高的文档. 全文检索最重要的两个方面是: 相关度(Relevance) 根据文档 ...
- 洛谷P3355 骑士共存问题
题目描述 在一个 n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入 对于给定的 n*n 个方格的国际象棋棋盘和障碍标志,计算棋盘上最多可以放置 ...
- flex RemoteObject 的两种使用方法
这里使用的是django1.6 和 postgreSQL9.0 FlashBuilder4.5 django方面就不说了,根据文档来做,建好模块,配置好数据库等等 创建 gateway 和 time ...