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. 【PAT甲级】1009 Product of Polynomials (25 分)

    题意: 给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数. trick: 这道题数据未知,导致测试的时候发现不了问题所在. 用set统计非零项时,通过set.siz ...

  2. 《Interest Rate Risk Modeling》阅读笔记——第九章:关键利率久期和 VaR 分析

    目录 第九章:关键利率久期和 VaR 分析 思维导图 一些想法 有关现金流映射技术的推导 第九章:关键利率久期和 VaR 分析 思维导图 一些想法 在解关键方程的时候施加 \(L^1\) 约束也许可以 ...

  3. ASP.NET MVC Web项目中使用Log4Net记录日志,并按照日志类型分文件存储

    1.创建MvcLog4Net项目 2.创建 空的MVC项目 3.项目创建完成的效果 4.选择项目,点击鼠标右键,在弹出菜单中选择“管理解决方案的 NuGet 程序包” 5. 在NuGet浏览界面: 点 ...

  4. 你知道HTTP协议的ETag是干什么的吗?

    前言 在HTTP1.1规范中,新增了一个HTTP头信息:ETag.对于普通开发者来说,可能平时真的不会接触到该HTTP头.平时接触不到或者说用得少,不代表这个请求头不重要.ETag使用得当,是可以减少 ...

  5. 回文串[APIO2014](回文树)

    题目描述 给你一个由小写拉丁字母组成的字符串 s.我们定义 s 的一个子串的存在值为这个子串在 s中出现的次数乘以这个子串的长度.对于给你的这个字符串 s,求所有回文子串中的最大存在值. 输入格式 一 ...

  6. Linux进程通信方式

    参考:https://www.cnblogs.com/yangykaifa/p/7295863.html

  7. jqGrid 复选框实现单选

    参考:https://blog.csdn.net/java0311/article/details/45575517

  8. Adroid ViewPage+GridView实现每页6个元素,三页滑动切换

    //}//public class MainActivity extends Activity {// private static final float APP_PAGE_SIZE = 16.0f ...

  9. AngularJS1.X指令

    <!DOCTYPE html> <html ng-app='myApp'> <head> <meta charset="utf-8"> ...

  10. 4、mysql查询练习

    1.创建四个表供查询 (1)学生表—Student 学号 姓名 性别 出生年月日 所在班级 [语句] > create table student( -> sno varchar(20) ...