好吧,非C++选手只好对极其好用的STL望而兴叹了QAQ。
多么显然的map映射啊。
强烈建议STL初学者试着一A。
CodeForces2A Winner
题目描述
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 “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.
输入输出格式
输入格式
The first line contains an integer number $n \; 1 \leq n \leq 1000$, $n$ is the number of rounds played. Then follow n lines, containing the information about the rounds in “name score” format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
输出格式
Print the name of the winner.
INPUT & OUTPUT ‘s example
Input’s eg #1
1 | 3 |
Output’s eg #1
1 | andrew |
Input’s eg #2
1 | 3 |
Outputs’s eg #2
1 | andrew |
题意翻译
原链接自己看QAQ
分析
经典的STLmap练手题对吧。
map就是STL中的映射模板,映射是个术语,指两个元素的集之间元素相互“对应”的关系,为名词。映射,或者射影,在数学及相关的领域经常等同于函数。 基于此,部分映射就相当于部分函数,而完全映射相当于完全函数。
比如,Rain_Delete上次数学考试考了95,那么Rain_Delete这个名字就在map中对应95这个分数。
定义方法:
1 |
|
在这个定义中,变量B,就称为相对于变量A的映射。
如何使用?
如果我们要对于string
类型的变量Rain_Delete
所映射的int
类型的变量值+10
的话,就可以这么写:1
2string s="Rain_Delete";
map[s]+=10;
很简单,对吧?
来讲这道题
我们把输入数据中的人名和分数对应为string
类型相对于int
类型的map映射。
然后对每一次输入中的分数以其相对应的人名进行操作(+或-)。
但有可能会出现比赛结束后最大分相等的情况。所以我们就要结束之后再$O(n)$访问一遍,查找第一次大于等于最大分的情况。
代码
1 | /* Headers */ |