『题解』Codeforces2A Winner
Portal
Portal1: Codeforces
Portal2: Luogu
Description
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "\(\texttt{name score}\)", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to \(m\)) at the end of the game, than wins the one of them who scored at least \(m\) points first. Initially each player has \(0\) points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input
The first line contains an integer number \(n(1 \le n \le 1000)\), \(n\) is the number of rounds played. Then follow \(n\) lines, containing the information about the rounds in "\(\texttt{name score}\)" format in chronological order, where \(\texttt{name}\) is a string of lower-case Latin letters with the length from \(1\) to \(32\), and \(\texttt{score}\) is an integer number between \(-1000\) and \(1000\), inclusive.
Output
Print the name of the winner.
Sample Input1
3
mike 3
andrew 5
mike 2
Sample Output1
andrew
Sample Input2
3
andrew 3
andrew 2
mike 5
Sample Output2
andrew
Description in Chinese
在Berland
流行着纸牌游戏“Berlogging
”,这个游戏的赢家是根据以下规则确定的:在每一轮中,玩家获得或失去一定数量的分数,在游戏过程中,分数被记录在“名称和得分”行中,其中名字是玩家的名字,得分是在这一轮中获得的分数。得分是负值意味着玩家失去了相应的分数。如果在比赛结束时只有一名玩家分数最多,他就是获胜者。如果两名或两名以上的玩家在比赛结束时都有最大的分数\(m\),那么其中首先获得至少\(m\)分的玩家胜利。开始时,每个玩家都是\(0\)分。保证在比赛结束时至少有一个玩家的分数为正。
Solution
把每个人的得分存到\(\texttt{map}\)里,然后求出最大得分,再寻找最先到达最大得分的人,即为获胜者。
Code
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
const int INF = 0x3f3f3f3f, MAXN = 1005;
int n, a[MAXN];
string name[MAXN];
map<string, int> Map1, Map2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> name[i] >> a[i];
Map1[name[i]] += a[i];
}//映射到map里
int Max = -INF;
for (int i = 0; i < n; i++)
if (Map1[name[i]] > Max) Max = Map1[name[i]];//求出最大得分
for (int i = 0; i < n; i++) {
Map2[name[i]] += a[i];
if (Map2[name[i]] >= Max && Map1[name[i]] >= Max) {
cout << name[i] << endl;//输出最先到最大得分的人
return 0;
}
}
return 0;
}
『题解』Codeforces2A Winner的更多相关文章
- 『题解』洛谷P1063 能量项链
原文地址 Problem Portal Portal1:Luogu Portal2:LibreOJ Portal3:Vijos Description 在\(Mars\)星球上,每个\(Mars\)人 ...
- 『题解』Codeforces1142A The Beatles
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently a Golden Circle of Beetlovers ...
- 『题解』Codeforces1142B Lynyrd Skynyrd
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently Lynyrd and Skynyrd went to a ...
- 『题解』洛谷P1993 小K的农场
更好的阅读体验 Portal Portal1: Luogu Description 小\(K\)在\(\mathrm MC\)里面建立很多很多的农场,总共\(n\)个,以至于他自己都忘记了每个农场中种 ...
- 『题解』洛谷P2296 寻找道路
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 在有向图\(\mathrm G\)中,每条边的长度均为\(1\),现给定起点和终点 ...
- 『题解』洛谷P1351 联合权值
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 无向连通图\(\mathrm G\)有\(n\)个点,\(n - 1\)条边.点从 ...
- 『题解』Codeforces656E Out of Controls
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description You are given a complete undirected gr ...
- 『题解』洛谷P2170 选学霸
更好的阅读体验 Portal Portal1: Luogu Description 老师想从\(N\)名学生中选\(M\)人当学霸,但有\(K\)对人实力相当,如果实力相当的人中,一部分被选上,另一部 ...
- 『题解』洛谷P1083 借教室
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Portal3: Vijos Description 在大学期间,经常需要租借教室.大到院系举办活动,小到 ...
随机推荐
- mpvue 星星打分组件
上图: <template> <div class="container"> <div v-for="(star,index) in sta ...
- windows服务器多端口Redis安装步骤
1.从官网获取最新稳定版redis文件.按端口号复制多个文件,比如6379和6380端口的文件包, 修改各自Conf文件的port号,分别为6379和6380.然后重命名为redis6379.conf ...
- System NT Kernel & System占用CPU 12%左右 终极解决方案,原来是更新惹的祸
任务管理器发现 system进程持续占用12%左右的cpu,网上搜索到的很多方法均无效 误打误撞发现了这个方法,亲测可用 卸载系统补丁(KB41000347),提升10%的cpu性能 卸载补丁前: ...
- cobalt strike笔记-常用beacon扫盲
最近还是重新补一下cs的东西 0x01 Beacon命令 Beacon Commands =============== Command Description ------- ----------- ...
- CSS中各种布局的背后(*FC)
CSS中各种布局的背后,实质上是各种*FC的组合.CSS2.1中只有BFC和IFC,CSS3 中还增加了FFC和GFC. 盒模型(BoxModel) 上图为W3C标准盒模型,另外还有一种IE盒模型(I ...
- webapck 按需加载及版本控制问题
在启用webpack的懒加载(按需加载)后,我们会遇到要解决缓存的问题. 解决缓存问题有几种方法: 第一种就是加个hash值.便每次修改后所编译后的文件名都不一样.这样能达到预期解决缓存的效果.具体设 ...
- Controller层的方法访问标志与Spring装配与AspectJ切面处理
最近在做AspectJ实现的日志模块,在spring配置中加入了<aop:aspectj-autoproxy/>,之后发现,只要有用到自定义注解的类,某些方法经MVC请求时就报空指针错误. ...
- Cocos2d-x 学习笔记(25) 渲染 绘制 Render
[Cocos2d-x]学习笔记目录 本文链接:https://www.cnblogs.com/deepcho/p/cocos2dx-render.html 1. 从程序入口到渲染方法 一个Cocos2 ...
- 使用Docker搭建apache环境
Docker搭建apache环境 前言 操作机:ubuntu16 x64 Dockers servion 18.09.7 下载镜像 使用docker pull 拉取最新的 apache镜像 命令:do ...
- ESP8266开发之旅 网络篇⑧ SmartConfig——一键配网
授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.希望大家分享给你周边需要的朋友或者同学,说不定大神成长之路有博哥的奠基石... QQ技术互动交流群:ESP8266&3 ...