CodeForce 841 A/B/C 解题报告

A Generous Kefa

题目大意:

一共有n个物品,k个人。每一个物品都有自己的颜色,颜色相同意味着同一件物品。现在要把所有的物品分出去,如果有人拿到了相同的物品就会不高兴。问是否存在方案使得每一个人都高兴?

大致思路:

给每一个物品开一个桶,然后按照顺序把物品放到桶里,最后扫一遍桶,如果有桶里物品的数目大于人数,那么根据抽屉原理可以知道必然有有人会拿到相同的物品

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     ios::sync_with_stdio(false);
 6     int button[26];
 7     int n,k;
 8     char color[110];
 9     memset(button,0,sizeof(button));
10     cin>>n>>k;
11     cin>>color;
12     for(int i=0;i<n;++i)
13         button[color[i]-‘a‘]++;
14     bool flag=true;
15     for(int i=0;i<26;++i)
16         if(button[i]>k){
17             flag=false;
18             break;
19         }
20     if(flag)
21         cout<<"YES"<<endl;
22     else
23         cout<<"NO"<<endl;
24     return 0;
25 }

B Godsend

题目大意:

第一个人能够拿走和为奇数的序列,第二个人能够拿走和为偶数的序列,如果轮到某人时发现序列已为空,或者没有能拿走的序列,则另一个人获胜。现在给你一个序列,问如果两个人都足够聪明,那么谁必将获胜。

大致思路:

仔细思考整个过程,可以发现;

一旦整个序列和为奇数,则第一个人可以直接把整个序列拿走然后获得胜利。所以当序列中存在奇数时,如果和是奇数则第一个人直接胜利,若是偶数,则拿走和为奇数的序列。剩下和为奇数的序列,无论第二个人怎么拿,都不会改变整个序列和的奇偶性,第一个人第二次拿的时候必定能把序列全部拿完从而获得胜利。

所以,只要序列中存在奇数,则第一个人获胜。若不存在,则第二个人获胜。

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     ios::sync_with_stdio(false);
 6     int n,a;
 7     bool flag=false;
 8     cin>>n;
 9     for(int i=0;i<n;++i){
10         cin>>a;
11         if(a%2)
12             flag=true;
13     }
14     if(flag)
15         cout<<"First"<<endl;
16     else
17         cout<<"Second"<<endl;
18     return 0;
19 }

C  Leha and Function

这个题我纯粹看样例答案猜规律的,没想到真猜出来了,就不写思路和大意了。

发现的规律如下:比如下面序列中某一个数在下面序列中排第K个,则对应上面的序列按大小排序后的第N-K个。

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=2e5+7;
 4 int a[maxn],ans[maxn];
 5 struct node{
 6     int v,id;
 7 }b[maxn];
 8 bool cmp(node a,node b)
 9 {
10     return a.v>b.v;
11 }
12 int main()
13 {
14     ios::sync_with_stdio(false);
15     int n,pos;
16     cin>>n;
17     for(int i=0;i<n;++i)
18         cin>>a[i];
19     for(int i=0;i<n;++i){
20         cin>>b[i].v;
21         b[i].id=i;
22     }
23     sort(a,a+n);
24     sort(b,b+n,cmp);
25     for(int i=0;i<n;++i){
26         pos=b[i].id;
27         ans[pos]=a[i];
28     }
29     for(int i=0;i<n;++i){
30         if(i)
31             cout<<" ";
32         cout<<ans[i];
33     }
34     cout<<endl;
35     return 0;
36 }

时间: 2024-08-06 21:35:01

CodeForce 841 A/B/C 解题报告的相关文章

CodeForce 837 A/B/C解题报告

A Text Volume 题面: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calcula

解题报告 之 POJ3057 Evacuation

解题报告 之 POJ3057 Evacuation Description Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time

hdu 1541 Stars 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有比它低层(或者同层)的或者在它左手边的星星数决定.计算出每个等级(0 ~ n-1)的星星各有多少颗. 我只能说,题目换了一下就不会变通了,泪~~~~ 星星的分布是不是很像树状数组呢~~~没错,就是树状数组题来滴! 按照题目输入,当前星星与后面的星星没有关系.所以只要把 x 之前的横坐标加起来就可以了

【百度之星2014~初赛(第二轮)解题报告】Chess

声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站,因此,笔者添加此条声明. 郑重声明:这篇记录<[百度之星2014~初赛(第二轮)解题报告]Chess>转载自 http://tiankonguse.com/ 的这条记录:http://tiankonguse.com/record/record.php?id=667 前言 最近要毕业了,有半年没做

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh童鞋的提醒. 勘误2:第7题在推断连通的时候条件写错了,后两个if条件中是应该是<=12 落了一个等于号.正确答案应为116. 1.煤球数目 有一堆煤球.堆成三角棱锥形.详细: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成三角形), 第四层10个(排列成三角形). -. 假设一共

[noip2011]铺地毯(carpet)解题报告

最近在写noip2011的题,备战noip,先给自己加个油! 下面是noip2011的试题和自己的解题报告,希望对大家有帮助,题目1如下 1.铺地毯(carpet.cpp/c/pas) [问题描述]为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有n 张地毯,编号从1 到n.现在将这些地毯按照编号从小到大的顺序平行于坐标轴先后铺设,后铺的地毯覆盖在前面已经铺好的地毯之上.地毯铺设完成后,组织者想知道覆盖地面某个点的最上面的那张地毯的

ACdream 1203 - KIDx&#39;s Triangle(解题报告)

KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description One day, KIDx solved a math problem for middle students in seconds! And than he created this problem. N

解题报告 之 CodeForces 91B Queue

解题报告 之 CodeForces 91B Queue Description There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue.

解题报告 之 POJ1226 Substrings

解题报告 之 POJ1226 Substrings Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings. Input The first li