题目描述:

在 Berland 流行着纸牌游戏 “Berlogging” ,这个游戏的赢家是根据以下规则确定的:在每一轮中,玩家获得或失去一定数量的分数,在游戏过程中,分数被记录在“名称和得分”行中,其中名称是玩家的名字,得分是在这一轮中获得的分数。得分是负值意味着玩家失去了相应的分数。如果在比赛结束时只有一名玩家分数最多,他就是获胜者。如果两名或两名以上的玩家在比赛结束时都有最大的分数 m,那么其中首先获得至少 m 分的玩家胜利。开始时,每个玩家都是0分。保证在比赛结束时至少有一个玩家的分数为正。

输入格式:

第一行包含整数n(1 <= n <= 1000),n 是游戏进行的的回合数。

第 2 ~ n+1 行,按照时间顺序输入“名称和得分”行的信息,其中名称是长度不大于 32 的小写字母组成的字符串,分数的绝对值不大于 1000。

输出格式:

输出获胜者的名称。

分析:利用map可以很快的解出这道题,在map中找value的最大值的时候,网上大部分的代码都是去遍历一遍,我在这里为了让自己更加熟练练习STL,就写了哥按照vaule排序的函数。另外,有可能会出现比赛结束后最大分相等的情况。所以我们就要结束之后再访问一遍,查找第一次大于等于最大分的情况。这也是m1出现的意义。。。

 #include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
#include<cstdlib>
using namespace std;
#define maxn 1010
int MIN=-;
string name[maxn];
int score[maxn];
bool flag(pair<string,int>o1 , pair<string,int>o2){
return o1.second>o2.second;
}
map<string,int> m,m1;/*m记录最大值,m1进行重新统计,找到第一次达到分数的人*/
int main(){
int n;
string name_max;//记录结果人名
cin>>n;
for( int i=; i<n; i++ ){
cin>>name[i]>>score[i];
m[name[i]]+=score[i];
}
vector< pair<string,int> > dic(m.begin(),m.end());
sort(dic.begin(),dic.end(),flag);
int temp_maxn=dic[].second;
for(int i=; i<n; i++ ){
m1[name[i]]+=score[i];//重新进行统计
if(m[name[i]]==temp_maxn&&m1[name[i]]>=temp_maxn){
name_max=name[i];
break;
}
}
cout<<name_max;
return ;
}

CF2A Winner的更多相关文章

  1. cf2A Winner(implementation)

    题意: N个回合. 每个回合:name score[名为name的这个人得了score分(可负可正)]. 问最后谁的累积分数是最高的.设为M.如果有好几个都得了M,找出这几个人中哪个最早回合累积分数超 ...

  2. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  3. HDU 2509 Be the Winner nim博弈变形

    Be the Winner Problem Description   Let's consider m apples divided into n groups. Each group contai ...

  4. HDU5754 Life Winner Bo(博弈)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life Winner" ...

  5. Codeforces Beta Round #2 A. Winner

    A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...

  6. HDU2509 Be the Winner

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang

    Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang Recruit Ponpare is Japan's leading ...

  8. winner tree 胜者树

    在树形选择排序中,利用锦标赛思想建立的树称为胜者树. 1.每个非终端节点存储的是左右孩子节点中的优胜者. 2.通过减少比较次数,提高效率. 3.胜者树就是一颗特殊的线段树. 一.构建树 Procedu ...

  9. cf------(round 2)A. Winner

    A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...

随机推荐

  1. Mac上搭建ELK

    转载自我的个人博客:http://blog.ywheel.cn/post/2017/03/04/setup_elk_on_mac/ 最近的项目需要对文本数据各字段进行快速检索.组合查询.模糊查询,在架 ...

  2. mac下host配置 + mac修改了环境变量却不生效:zsh: command not found: xxx

    https://blog.csdn.net/hlllmr1314/article/details/52228672 在/etc/profile中配置了go语言环境变量: export GOROOT=/ ...

  3. 我的Linux操作系统的发行版是什么?版本号是什么?

    可以用下面的两个命令来查看: cat /etc/*-release hostnamectl 参考资料 ============== How To Find Out My Linux Distribut ...

  4. Android开发中常见的设计模式 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  5. [Python设计模式] 第19章 分公司=部门?——组合模式

    github地址:https://github.com/cheesezh/python_design_patterns 组合模式 组合模式,将对象组合成树形结构以表示"部分-整体" ...

  6. API 'variant.getJavaCompiler()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'

    WARNING: API 'variant.getJavaCompiler()' is obsolete and has been replaced with 'variant.getJavaComp ...

  7. [Java] 绕过证书验证调 HTTPS 接口时报 “SSLHandshakeException: DHPublicKey does not comply to algorithm constraints”的解决办法

    作者: zyl910 一.缘由 最近有在对接一个无证书的HTTPS接口时,总是收到"SSLHandshakeException: DHPublicKey does not comply to ...

  8. Linux远程执行shell命令

    Linux远程执行shell命令   在Linux系统中,我们经常想在A机器上,执行B机器上的SHELL命令. 下面这种方案,是一种流行可靠的方案. 1.SSH无密码登录 # 本地服务器执行(A机器) ...

  9. 关于4A(统一安全管理平台)系统的理解

    1. 4A系统的需求分析 近年来企业用户的业务系统发展十分迅速,内部的系统数和用户数不断增加,网络规模迅速扩大,在应用扩展的同时,各业务系统的安全管理工作相对滞后,无法满足企业发展的长期要求. 各系统 ...

  10. Java之NIO

    想要学习Java的Socket通信,首先要学习Java的IO和NIO基础,这方面可以阅读<Java NIO 系列教程>. 下面展示自己代码熟悉Java的NIO编程的笔记. 1.缓冲区(Bu ...