Codeforces Round #429 (Div. 2)ABC

A:

题意:n个东西,k个朋友,全部给朋友,每个朋友不可以拿同样的,问是否可行

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 map<char ,int >ma;
 5 int main(){
 6     int n,k;
 7     cin>>n>>k;
 8     string s;
 9     cin>>s;
10     for(int i=0;i<n;i++){
11         ma[s[i]]++;
12         if(ma[s[i]]>k){
13             cout<<"NO"<<endl;return 0;
14         }
15     }
16     cout<<"YES"<<endl;
17     return 0;
18 }

B

题意:A可以选任意不为0长度的和为奇数的数字,B可以选任意不为0长度的和为偶数的数字,问谁赢

思路:奇数+奇数=偶数,如果和为奇数,A赢,如果为偶数且有一个奇数,A赢

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4
 5 ll a[1000005];
 6
 7 int main(){
 8     int n;
 9     cin>>n;
10     ll x,sum=0,t=0;
11     for(int i=1;i<=n;i++){
12         scanf("%lld",&x);
13         sum+=x;
14         if(x&1) t=1;
15     }
16     if(sum&1) cout<<"First"<<endl;
17     else {
18         if(t) cout<<"First"<<endl;
19         else cout<<"Second"<<endl;
20     }
21     return 0;
22 }

C

题意:a重新排序,问f(ai,bi)最大,f(a,b)为从1-a种选择b个数字,最小的那个数字的贡献

思路:推一推即可发现,最小的b配最大的a

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 struct node{
 5     int  x;
 6     int y;
 7     int id;
 8 }b[200005];
 9 int a[200005];
10 bool cmp(node p,node q){
11     return p.x>q.x;
12 }
13 bool cmp1(node p,node q){
14     return p.id<q.id;
15 }
16 int main(){
17     int n;
18     cin>>n;
19     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
20     for(int i=1;i<=n;i++){
21         scanf("%d",&b[i].x);
22         b[i].id=i;
23     }
24     sort(a+1,a+1+n);
25     sort(b+1,b+1+n,cmp);
26     for(int i=1;i<=n;i++) b[i].y=a[i];
27     sort(b+1,b+1+n,cmp1);
28     for(int i=1;i<=n;i++){
29         printf("%d ",b[i].y);
30     }
31 }
时间: 2024-08-05 05:07:41

Codeforces Round #429 (Div. 2)ABC的相关文章

Codeforces Round #247 (Div. 2) ABC

Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/WayToACM/tree/master/CodeForces/431 A - Black Square 题目地址 题意: Jury玩别踩白块,游戏中有四个区域,Jury点每个区域要消耗ai的卡路里,给出踩白块的序列,问要消耗多少卡路里. 分析: 模拟水题.. 代码: /* * Author: illuz

CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)

思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上差分 ] | Codeforces Round #429(Div 1) 题意: 选择一个边集合,满足某些点度数的奇偶性 分析: 将d = 1的点连成一颗树,不在树上的点都不连边. 可以发现,当某个节点u的所有子节点si均可操控 (u, si) 来满足自身要求 即整棵树上至多只有1个点不满足自身要求,

CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)

/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #include <bits/stdc++.h> using namespace std; const int N = 2e5+5; int a[N], b[N], c[N], n; int aa[N], bb[N]; bool cmp1(int x, int y) { return a[x] > a[y

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo

Codeforces Round #451 (Div. 2) ABC

A. Rounding Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 

【推导】【DFS】Codeforces Round #429 (Div. 1) B. Leha and another game about graph

题意:给你一张图,给你每个点的权值,要么是-1,要么是1,要么是0.如果是-1就不用管,否则就要删除图中的某些边,使得该点的度数 mod 2等于该点的权值.让你输出一个留边的方案. 首先如果图内有-1,那么必有解.否则如果初始不合法的点数为偶数,那么必有解,否则无解.因为删一条边,要么使图中不合法的点数+2,要么不变,要么-2. 如果有解,构造图的任意一个生成树,如果有-1,就让-1为根,否则任意结点为根.然后从叶子向根定每个点的入度数,由于自底向上,一个结点的儿子边都被处理完后,只需要决定父边

Codeforces Round #312 (Div. 2) ABC题解

[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地.拉拉土地是一个非常美丽的国家,位于坐标线.拉拉土地是与著名的苹果树越来越随处可见. 拉拉土地恰好n苹果树.树数i位于位置xi和具有人工智能的苹果就可以了增长.阿姆鲁希望从苹果树收集苹果. AMR目前维持在X =0的位置.在开始的时候,他可以选择是否去左边或右边.他会在他的方向继续下去,直到他遇见一棵苹果树,他之前没有参观.他会采取所有的苹果,然后扭转他的方向,继续走这

Codeforces Round#429(Div.2)

A. Generous Kefa 如果有字母的个数大于k则NO #include<bits/stdc++.h> using namespace std; int arr[28],n,k; string str; int main(){ cin>>n>>k; cin>>str; for(int i = 0;i<str.length();i++){ arr[(int)(str[i]-'a')]++; } for(int i = 0;i<26;i++)

【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最大. [算法]数学结论+数学期望+排序 [题解]很无奈,这题放在div2 C,难以推导的期望公式,广为人知的结论,容易观察样例得出的做法,都体现了这道题的不合理性. F(n,k)=(n+1)/(k+1) 公式推导可能触及我的知识盲区了QAQ 得到公式后,显然要求k尽可能小,n尽可能大,经验告诉我们随着两数