Codeforces 2A :winner
1 second
64 megabytes
standard input
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.
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.
Print the name of the winner.
3
mike 3
andrew 5
mike 2
andrew
3
andrew 3
andrew 2
mike 5
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的更多相关文章
- CodeForces 2A Winner
Winner Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- codeforces 2A Winner (好好学习英语)
Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...
- CodeForces 2A - Winner(模拟)
题目链接:http://codeforces.com/problemset/problem/2/A A. Winner time limit per test 1 second memory limi ...
- Codeforces 731C:Socks(并查集)
http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...
- Codeforces 747D:Winter Is Coming(贪心)
http://codeforces.com/problemset/problem/747/D 题意:有n天,k次使用冬天轮胎的机会,无限次使用夏天轮胎的机会,如果t<=0必须使用冬轮,其他随意. ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
- Codeforces 749D:Leaving Auction(set+二分)
http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- Codeforces 749C:Voting(暴力模拟)
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...
随机推荐
- Linux centosVMware Nginx负载均衡、ssl原理、生成ssl密钥对、Nginx配置ssl
一.Nginx负载均衡 vim /usr/local/nginx/conf/vhost/load.conf // 写入如下内容 upstream qq_com { ip_hash; 同一个用户始终保持 ...
- Linux centos7 LAMP架构介绍、 MySQL、MariaDB介绍、MySQL安装
一.LAMP架构介绍 为Linux+Apache(httpd)+MySQL+PHP简写,把后三者安装在Linux Apache是最常用的的web服务软件,MySQL为小型的数据库存储软件,PHP为脚本 ...
- Linux centos7iptables filter表案例、iptables nat表应用
一.iptables filter表案例 vim /usr/local/sbin/iptables.sh 加入如下内容 #! /bin/bash ipt="/usr/sbin/iptable ...
- 去除input边框 input去除边框 去除input获取焦点时的蓝色外边框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 警示框UIAlertController的使用(看完马上会用!!)
本文尽量图文并茂,并且提供对应的代码,确保看到这篇文章马上能够上手使用UIAlertController控件.-我要兑现我的务实宣言- 本文构思: 1.出具效果图,通过这种最直接方式了解该控件的展示效 ...
- sklearn实现决策树算法
1.决策树算法是一种非参数的决策算法,它根据数据的不同特征进行多层次的分类和判断,最终决策出所需要预测的结果.它既可以解决分类算法,也可以解决回归问题,具有很好的解释能力.另外,对于决策树的构建方法具 ...
- F: Fabulous Race Between Tortoise And Rabbit 扩展欧几里得
http://oj.jxust.edu.cn/contest/Problem?id=1561&pid=5 题目描述 经历了上次的惨败,兔子一直心怀不满,又策划了一场比赛,但这次不再是简单的跑步 ...
- 七 MyBatis整合Spring,DAO开发(传统DAO&动态代理DAO)
整合思路: 1.SQLSessionFactory对象应该放到Spring中作为单例存在 2.传统dao开发方式中,应该从Spring容器中获得SqlSession对象 3.Mapper代理行驶中,应 ...
- vue-cli 初始化项目时开发环境中的跨域问题
最近刚刚完成自己的毕业设计(基于Vue的信息资讯展示与管理平台),于是想整理一下过程遇到的一些问题. 项目基于Vue开发,使用 Vue-cli 初始化项目文件目录时默认占用8080端口,而我又想使用 ...
- redis提供的持久化机制(rdb,aof)
Redis提供的持久化机制 Redis是一种面向“key-value”类型数据的分布式NoSQL数据库系统,具有高性能.持久存储.适应高并发应用场景等优势.它虽然起步较晚,但发展却十分迅速. 近日,R ...