CodeForces 2A Winner
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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 Input
3
mike 3
andrew 5
mike 2
andrew
3
andrew 3
andrew 2
mike 5
andrew 这道题不难,主要是先确定最大的分数是多少,然后确定最后达到最大分数的人有那些。然后再次模拟整个过程,在达到最大分数的人中选出第一个达到或者超过最大分数的人。
#include<iostream>
#include<map>
using namespace std;
const int maxx=;
struct Node
{
string name;
int grade;
} stu[maxx];
int main()
{
int n;
string ans="";
scanf("%d",&n);
string name;
int max=;
map<string,int>m;
for(int i=; i<n; i++)
{
string name;
int a;
cin>>name>>a;
stu[i].name=name;
stu[i].grade=a;
if(m.count(name))
m[name]+=a;
else
{
m.insert(pair<string,int>(name,a));
}
}
map<string,int>nm;
map<string,int>::iterator iter;
for(iter=m.begin(); iter!=m.end(); iter++)
{
// cout<<iter->first<<" "<<iter->second<<endl;
if(iter->second>max)
{
nm.clear();
nm.insert(pair<string,int>(iter->first,)); max=iter->second;
}
else if(iter->second==max)
{
nm.insert(pair<string,int>(iter->first,));
}
}
m.clear();
//cout<<max;
for(int i=; i<n; i++)
{
if(m.count(stu[i].name))
{
m[stu[i].name]+=stu[i].grade;
if((m[stu[i].name]>=max)&&(nm.count(stu[i].name)))
{
ans=stu[i].name;
break;
}
}
else
{
m.insert(pair<string,int>(stu[i].name,stu[i].grade));
if((m[stu[i].name]>=max)&&(nm.count(stu[i].name)))
{
ans=stu[i].name;
break;
}
}
}
cout<<ans<<endl;
}
CodeForces 2A Winner的更多相关文章
- 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 2A :winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- CodeForce 2A Winner
很多人玩一个游戏,每一轮有一个人得分或者扣分,最后分数最高的人夺冠:如果最后有多个人分数都是最高的,则这些人里面,在比赛过程中首先达到或者超过这个分数的人夺冠.现在给定最多1000轮每轮的情况,求最后 ...
- Codeforces Beta Round #2 A. Winner 水题
A. Winner 题目连接: http://www.codeforces.com/contest/2/problem/A Description The winner of the card gam ...
- Codeforces Beta Round #2 A. Winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- codeforces Winner
/* * Winner.cpp * * Created on: 2013-10-13 * Author: wangzhu */ /** * 先找出所有选手的分数和中最大的分数和,之后在所有选手的分数和 ...
- Codeforces Gym100952 A.Who is the winner? (2015 HIAST Collegiate Programming Contest)
A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input stan ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! 二分
C. Everyone is a Winner! On the well-known testing system MathForces, a draw of n rating units is ar ...
随机推荐
- 再谈JavaScript的数据类型问题
JavaScript的数据类型问题已经讨论过很多次了,但许多人还有许多书仍然沿用着错误的.混乱的一些观点,所以就再细讲一回. 提及这个讨论的原因在于argb同学在我的MSN博客上的一段回复,又更早的起 ...
- 【python】Django设置SESSION超时时间没有生效?
按手册和网上的方法在settings.py中设置“SESSION_COOKIE_AGE” 和 “SESSION_EXPIRE_AT_BROWSER_CLOSE” 均不生效. 通过查看django的源代 ...
- Logon database Tiger引起DataGuard不同步问题
当DataGuard升级CPU后.发现主备库不能同步了,日志报错,所以在主库的运行的升级的后脚本"@catbundle.sql cpu apply"不能同步到备库 现象: brok ...
- [笔记][Java7并发编程实战手冊]3.8 并发任务间的数据交换Exchanger
[笔记][Java7并发编程实战手冊]系列文件夹 简单介绍 Exchanger 是一个同步辅助类.用于两个并发线程之间在一个同步点进行数据交换. 同意两个线程在某一个点进行数据交换. 本章exchan ...
- CAS lock-free
转:http://www.cnblogs.com/lucifer1982/archive/2009/04/08/1431992.html http://en.wikipedia.org/wiki/Co ...
- 使用Visual Studio 2017编译opencv 3.2版本
一.背景介绍 opencv是一个很强大的开源的计算机视觉库,应用领域如人机互动,图像处理,人脸识别,和现实生活中智能设计的关系很紧密.现在官方提供的编译包中,c++的只提供了x64位的library, ...
- 如何下载HLS视频到本地(m3u8)
如何下载HLS视频到本地(m3u8)? CreateTime--2018年3月21日16:07:00 Author:Marydon 一.需求 很多连载的动漫需要VIP会员才能观看,而且有的由于版权 ...
- js经常使用功能代码
js经常使用功能代码(持续更新): 1---折叠与展开 <input id="btnDisplay" type="button" class=" ...
- 【Linux】cp命令
用途 cp除了复制功能之外还可以建立快捷方式 全称 cp的全称为copy 参数 -a :相当于同时指定参数pdr -d :若文件为链接文件的属性(link file),则复制链接文件属性而非档案本身 ...
- 【BIRT】02_开发一张简单的报表
上一节我们已经将开发环境准备完毕,那么接下来就开发一张简单的报表 1.BIRT开发环境 打开已经安装好的BIRT开发环境 1.1新建Project 菜单栏>> file >> ...