设为首页 收藏本站
查看: 994|回复: 0

[经验分享] codechef 20131月月赛大水题

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-26 08:48:07 | 显示全部楼层 |阅读模式
  http://www.codechef.com/JAN13/problems/CVOTE
  

Chef of the Year
  Problem code: CVOTE


  • Submit
  • My Submissions
  • All Submissions



  Chefs from all over the globe gather each year for an international convention. Each chef represents some country. Please, note that more than one chef can represent a country.
  Each of them presents their best dish to the audience. The audience then sends emails to a secret and secure mail server, with the subject being the name of the chef whom they wish to elect as the
"Chef of the Year".
  You will be given the list of the subjects of all the emails. Find the country whose chefs got the most number of votes, and also the chef who got elected as the
"Chef of the Year" (the chef who got the most number of votes).
  Note 1
  If several countries got the maximal number of votes, consider the country with the lexicographically smaller name among them to be a winner. Similarly if several chefs got the maximal number of votes, consider the chef with the lexicographically smaller
name among them to be a winner.
  Note 2
  The string A = a1a2...an is called lexicographically smaller then the string
B = b1b2...bm in the following two cases:


  • there exists index imin{n, m} such that
    aj
    = bj for 1 ≤ j < i and
    ai < bi;
  • A is a proper prefix of B, that is,
    n < m
    and aj = bj for
    1 ≤ j ≤ n.
  The characters in strings are compared by their ASCII codes.
  Refer to function strcmp in C or to standard comparator
<
for string data structure in C&#43;&#43; for details.

Input
  The first line of the input contains two space-separated integers N and
M denoting the number of chefs and the number of emails respectively. Each of the following
N lines contains two space-separated strings, denoting the name of the chef and his country respectively. Each of the following
M lines contains one string denoting the subject of the email.

Output
  Output should consist of two lines. The first line should contain the name of the country whose chefs got the most number of votes. The second line should contain the name of the chef who is elected as the
&quot;Chef of the Year&quot;.

Constraints


  • 1N10000 (104)
  • 1M100000 (105)
  • Each string in the input contains only letters of English alphabets (uppercase or lowercase)
  • Each string in the input has length not exceeding 10
  • All chef names will be distinct
  • Subject of each email will coincide with the name of one of the chefs

Example 1

Input:
1 3
Leibniz Germany
Leibniz
Leibniz
Leibniz
Output:
Germany
Leibniz

Example 2

Input:
4 5
Ramanujan India
Torricelli Italy
Gauss Germany
Lagrange Italy
Ramanujan
Torricelli
Torricelli
Ramanujan
Lagrange
Output:
Italy
Ramanujan

Example 3

Input:
2 2
Newton England
Euclid Greece
Newton
Euclid
Output:
England
Euclid

Explanation
  Example 1. Here we have only one chef Leibniz and he is from
Germany. Clearly, all votes are for him. So Germany is the country-winner and
Leibniz is the &quot;Chef of the Year&quot;.
  Example 2. Here we have chefs Torricelli and
Lagrange from Italy, chef Ramanujan from
India and chef Gauss from Germany.
Torricelli got 2 votes, while Lagrange got one vote. Hence the
Italy got 3 votes in all. Ramanujan got also 2 votes. And so
India got 2 votes in all. Finally Gauss got no votes leaving
Germany without votes. So the country-winner is Italy without any ties. But we have two chefs with 2 votes:
Torricelli and Ramanujan. But since the string
&quot;Ramanujan&quot;
is lexicographically smaller than &quot;Torricelli&quot;, then
Ramanujan is the &quot;Chef of the Year&quot;.
  Example 3. Here we have two countries with 1 vote: England and
Greece. Since the string &quot;England&quot; is lexicographically smaller than
&quot;Greece&quot;, then England is the country-winner. Next, we have two chefs with 1 vote:
Newton and Euclid. Since the string &quot;Euclid&quot; is lexicographically smaller than
&quot;Newton&quot;, then Euclid is the &quot;Chef of the Year&quot;.
  
  


  


  题意:  输入nm  n个字符串对     表示某个人对应某个国家
  然后输入 m个人  表示每个人得到的金牌数加1   对应的国家也要加1


  输出得到金牌数最多的国家 和 最多的人    相同的按字典序
  


  思路:
  3个map水体
  #include<string>
#include<stdio.h>
#include<map>
#include<string.h>
#include<iostream>
using namespace std;
map<string,string>mp1;
map<string,int>mp2;
map<string,int>mp3;
map<string,int>::iterator it,it1,it2;
int main()
{
int n,m,i,j,k;
char s1[100],s2[100];
char ans1[100],ans2[100];
while(scanf(&quot;%d %d&quot;,&n,&m)!=EOF)
{
mp1.clear();
mp2.clear();
mp3.clear();
while(n--)
{
scanf(&quot;%s %s&quot;,s1,s2);
mp1[s1]=s2;
}
while(m--)
{
scanf(&quot;%s&quot;,s1);
mp2[s1]++;
mp3[mp1[s1]]++;
// mp3[s1]++;
}
//strcpy(char_str,string_str.c_str());
int mmax=0;
for(it=mp2.begin();it!=mp2.end();it++)
{
if(it->second>mmax) {mmax=it->second;strcpy(ans1,it->first.c_str());}
}
mmax=0;
for(it=mp3.begin();it!=mp3.end();it++)
{
if(it->second>mmax) {mmax=it->second;strcpy(ans2,it->first.c_str());}
}
printf(&quot;%s\n%s\n&quot;,ans2,ans1);
//cout<<ans1<<ans2<<endl;
}
return 0;
}




  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143656-1-1.html 上篇帖子: configure chef replication 下篇帖子: Chef集中管理工具实践
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表