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
3
mike 3
andrew 5
mike 2
output
andrew
input
3
andrew 3
andrew 2
mike 5
output
andrew

做Codeforces上的题还很少,但只从这道题来说,这题无论从题意还是各个方面都足够有趣。一共有n轮比赛,接下来的每行代表这一轮比赛中,这个人得到的分数,分数可正可负。问最先到达最大分值的人是谁。

大一的时候做这个居然用的是数组,现在用map果然方便太多了,但还是因为一开始没注意有可能是负数导致,判断的时候出现了问题。

一共判断的时候有两轮,第一轮判断这个人的结果是不是最大值,如果是最大值,就要看它是不是第一个到达的,也即第二轮的成绩是不是大于或是等于最大值,如果满足条件,赶紧输出结果,就行了。最近做题被虐的都没人样了。。。

代码:

#include <iostream>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std; //一开始没有考虑到负数的情况,出现了错误。出现负数的话,分数就会下降,之前的最大值就不会对。 map<string,int> round;
map<string,int> round2; string name[1005];
int score[1005]; int main()
{
int count,i;
cin>>count; round.clear(); int max = -1000005;
string max_name; for(i=1;i<=count;i++)
{
cin>>name[i]>>score[i]; round[name[i]] += score[i];
} for(i=1;i<=count;i++)
{
if(round[name[i]]>max)
{
max=round[name[i]];
}
} for(i=1;i<=count;i++)
{
if(round[name[i]] == max)
{
round2[name[i]] += score[i]; if(round2[name[i]]>=max)//最先到达
{
cout<<name[i]<<endl;
return 0;
}
}
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Codeforces 2A :winner的更多相关文章

  1. CodeForces 2A Winner

    Winner Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. codeforces 2A Winner (好好学习英语)

    Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...

  3. CodeForces 2A - Winner(模拟)

    题目链接:http://codeforces.com/problemset/problem/2/A A. Winner time limit per test 1 second memory limi ...

  4. Codeforces 731C:Socks(并查集)

    http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...

  5. Codeforces 747D:Winter Is Coming(贪心)

    http://codeforces.com/problemset/problem/747/D 题意:有n天,k次使用冬天轮胎的机会,无限次使用夏天轮胎的机会,如果t<=0必须使用冬轮,其他随意. ...

  6. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  7. Codeforces 749D:Leaving Auction(set+二分)

    http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...

  8. Codeforces 749B:Parallelogram is Back(计算几何)

    http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...

  9. Codeforces 749C:Voting(暴力模拟)

    http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...

随机推荐

  1. 如何编写.gitignore文件

    为什么要有.gitignore文件 项目中经常会生成一些Git系统不需要追踪(track)的文件.典型的是在编译生成过程中 产生的文件或是编程器生成的临时备份文件.当然,你不追踪(track)这些文件 ...

  2. Eclipse之Cannot open Eclipse Marketplace

    今天给eclipse安装插件的时候出现各种cannot connect to...的问题, 想打开eclipse marketplace来安装插件出现Cannot open Eclipse Marke ...

  3. php中读取大文件实现方法详解

    php中读取大文件实现方法详解 来源:   时间:2013-09-05 19:27:01   阅读数:6186 分享到:0 [导读] 本文章来给各位同学介绍php中读取大文件实现方法详解吧,有需要了解 ...

  4. asp.net mvc 短信验证码

    把发短信功能写成一个类包,需要引用: SmsUtillity.cs: using System; using System.Collections.Generic; using System.Linq ...

  5. 洛谷 P5242 [USACO19FEB]Cow Dating P

    这道题很有意思. 不难发现,对于一个区间 \([l, r]\),恰好只有一个奶牛接受邀请的概率为 \[\prod_{i=l}^r(1-p_i) \cdot \sum_{i=l}^r \frac {p_ ...

  6. vue 父组件调用子组件方法简单例子(笔记)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 吴裕雄--天生自然HADOOP操作实验学习笔记:单节点伪分布式安装

    实验目的 了解java的安装配置 学习配置对自己节点的免密码登陆 了解hdfs的配置和相关命令 了解yarn的配置 实验原理 1.Hadoop安装 Hadoop的安装对一个初学者来说是一个很头疼的事情 ...

  8. Django的urls(路由)

    目录 Django的urls(路由) 正则表达式详解 路由匹配(分组匹配) 无名分组 有名分组 反向解析 无名分组反向解析 有名分组反向解析 路由分发 名称空间 虚拟环境 伪静态 Django的url ...

  9. 安装 primecoin 矿池

    壹.安装 boost_1_49_0. 一.官网下载:https://www.boost.org/users/download/ 前期准备:boost中,用到了别的函数库,所以为了使用boost中相应的 ...

  10. CH8 课后习题

    8.1和8.2 #include <iostream> using namespace std; istream& f(istream& in) { int v; in & ...