CodeForces 2A Winner(CodeForces的题意总是那么难理解)——Codeforces Beta Round #2

来源:互联网 发布:淘宝工作室是做什么 编辑:程序博客网 时间:2024/06/03 17:21

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

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.

Input

The first line contains an integer number n (1  ≤  n  ≤  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.

Output

Print the name of the winner.

Sample test(s)
input
3mike 3andrew 5mike 2
output
andrew
input
3andrew 3andrew 2mike 5
output
andrew

/*********************************************************************/

题意:对于CodeForces的题目,真心是有点难理解,或许是因为本人英语水平太差吧,至少这题一开始理解起来并不是像题目本身所要表达的意思那样。

其实此题就是有n个回合,每个回合给你一个人名,以及该回合此人的得分(此人在之前的回合可能出现过),问最终得分最高(暂且将最高分记为m)的人的名字。若有多个人均得到了最高分,则输出回合中得分最先大于等于m的人的名字。

解题思路:首先,题目明确指出过程中会出现得分为负的情况,一开始我理解成了过程中出现负分的话,此人直接淘汰,即不记录在最终评定最高分的人內。然而,orz,理解错误。

有一种情况是,某个人在过程中分数会暂时超过最终的最高分,这点要考虑进去

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 1001;const int inf = 1000000000;const int mod = 2009;struct node{    string s;    int k;}w[N];map<string,int> s,m;int main(){    int n,i,Max;    Max=-inf;    scanf("%d",&n);    for(i=0;i<n;i++)    {        cin>>w[i].s>>w[i].k;        s[w[i].s]+=w[i].k;//求出每个人最终的得分    }    for(i=0;i<n;i++)        if(Max<s[w[i].s])            Max=s[w[i].s];//记录最终得分的最高分    for(i=0;s[w[i].s]<Max||(m[w[i].s]+=w[i].k)<Max;i++);//找到最终得分为最高分且最先不小于最高分的人即为所求    cout<<w[i].s<<endl;    return 0;}
菜鸟成长记
0 0
原创粉丝点击