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. [转载]android 显示多选列表对话框setMultiChoiceItems

    public class MultiChoiceItemsTest extends Activity implements OnClickListener { private String[] pro ...

  2. nacos集群配置

    一.    环境准备 Nacos 依赖 java环境来运行.如果您是从代码开始构建并运行Nacos,还需要为此配置 Maven环境,请确保是在以下版本环境中安装使用: 64 bit OS,支持 Lin ...

  3. 树莓派4B踩坑指南 - (2)安装系统及初始化

    安装系统及初始化 格式化TF卡:SDFormatter 4.0.如果需要换系统,则必须先烧录进一个空img,然后再格式化! 烧录系统:Win32DiskImager-0.9.5 更改默认密码:账号pi ...

  4. Rcnn/Faster Rcnn/Faster Rcnn的理解

    基于候选区域的目标检测器 1.  滑动窗口检测器 根据滑动窗口从图像中剪切图像块-->将剪切的图像块warp成固定大小-->cnn网络提取特征-->SVM和regressor进行分类 ...

  5. redhat 7.6 ssh 服务配置

    安装ssh yum install openssh 查看端口 netstat -ntpl netstat -ntpl | grep :22 启动和关闭 service sshd restart/sta ...

  6. Day1-C-CF-1144A

    简述:给你一串字符,判断是否由连续字母构成且每个字符只出现一次 思路:用set直接储存,判断size和初末位置字母与size的关系即可 代码: #include<iostream> #in ...

  7. redis之string数据类型常用方法总结

    目录 redis 字符串(string)[需要掌握] 特点 语法 redis 字符串(string)[需要掌握] 特点 一个键能存储512MB数据 string类型是二进制安全的,可以存储任何数据,比 ...

  8. 课堂测试用javaweb写一个注册界面,并将数据保存到后台数据库(部分完成)

    今天我到现在为止,也只完成了数据库的连接,还没有写前台的javascript的检查输入的代码,打算周四前完成. 代码如下: package Dao; import java.sql.Connectio ...

  9. js原型链。。fuck

    function Person(name){ this.name = name; }; function Mother(){ }; //给mother提供公有的属性 Mother.prototype ...

  10. VUE 使用axios请求第三方接口数据跨域问题解决

    VUE是基于node.js,所以解决跨域问题,设置一下反向代理即可. 我这里要调用的第三方接口地址为 http://v.juhe.cn/toutiao/index?type=top&key=1 ...