Codeforces Beta Round #2 A. Winner 水题
A. Winner
题目连接:
http://www.codeforces.com/contest/2/problem/A
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
Sample Output
andrew
Hint
题意
现在有n个回合
每一回合给一个玩家的姓名和他这局的分数。
然后问结尾的时候,谁是赢家。
最高分是赢家。
如果最高分有多个,那么谁曾经最先大于等于这个分数的,就是赢家。
题解:
第一遍暴力扫最高分是谁。
第二遍扫谁最先到达最高分就好了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1200;
map<string,int> H,H1;
struct node
{
    string s;
    int score;
}op[maxn];
int main()
{
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>op[i].s>>op[i].score;
        H[op[i].s]+=op[i].score;
    }
    int ans=0;
    for(auto v:H)
        ans=max(v.second,ans);
    string Ans;
    for(int i=0;i<n;i++)
    {
        H1[op[i].s]+=op[i].score;
        if(H[op[i].s]==ans&&H1[op[i].s]>=ans)
        {
            Ans=op[i].s;
            break;
        }
    }
    cout<<Ans<<endl;
}												
											Codeforces Beta Round #2 A. Winner 水题的更多相关文章
- Codeforces Beta Round #37 A. Towers 水题
		
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
 - Codeforces Testing Round #12 A. Divisibility 水题
		
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
 - 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 Beta Round #3 C. Tic-tac-toe 模拟题
		
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...
 - 水题 Codeforces Beta Round #70 (Div. 2) A. Haiku
		
题目传送门 /* 水题:三个字符串判断每个是否有相应的元音字母,YES/NO 下午网速巨慢:( */ #include <cstdio> #include <cstring> ...
 - Codeforces Beta Round #5 B. Center Alignment 模拟题
		
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
 - Codeforces Beta Round #32 (Div. 2, Codeforces format)
		
Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...
 - Codeforces Beta Round #18 (Div. 2 Only)
		
Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc+ ...
 - Codeforces Beta Round #22 (Div. 2 Only)
		
Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 #include<bits/stdc+ ...
 
随机推荐
- Java21个基础知识点
			
类装载器就是寻找类的字节码文件,并构造出类在JVM内部表示的对象组件.在Java中,类装载器把一个类装入JVM中,要经过以下步骤: (1) 装载:查找和导入Class文件: (2) 链接:把类的二进制 ...
 - [caffe error] undefined reference to `inflateValidate@ZLIB_1.2.9'
			
undefined reference to `inflateValidate@ZLIB_1.2.9' Makefile.config添加一行LINKFLAGS := -Wl,-rpath,$(HOM ...
 - MD5加密学习
			
MD5(Message Digest --消息摘要算法)算法是一种散列(hash)算法(摘要算法,指纹算法),不是一种加密算法(易错),任何长度的任意内容都可以用MD5计算出散列值.主要作用是[验明“ ...
 - react项目中遇到的一些问题
			
推荐使用facebook官方构建工具create-react-app来创建React基础工程.(然而我还是手动构建) (路由)官方旧版本和V4的比较.https://github.com/ReactT ...
 - [会装]Spark standalone 模式的安装
			
1. 简介 以standalone模式安装spark集群bin运行demo. 2.环境和介质准备 2.1 下载spark介质,根据现有hadoop的版本选择下载,我目前的环境中的hadoop版本是2. ...
 - Winfrom窗体间传值
			
1.通过tag属性传输,tag属性是存储与空间密切相关的数据.比如登陆界面的数据传输给主界面. 子窗体 ...
 - MySQL-5.5.49安装、多实例、主从复制
			
源码安装mysql yum install ncurses-devel libaio-devel -y mkdir /server/tools -p cd /server/tools wget htt ...
 - Leetcode 之Length of Last Word(38)
			
做法很巧妙.分成左右两个对应的部分,遇到左半部分则入栈,遇到右半部分则判断对应的左半部分是否在栈顶.注意最后要判断堆栈是否为空. bool isValid(const string& s) { ...
 - thinkphp5 消息队列thinkphp-queue扩展
			
1.简介 thinkphp-queue是thinkphp的一个第三方扩展, 内置了 Redis,Database,Topthink ,Sync这四种驱动,推荐使用redis 2. 下载 和安装 com ...
 - Python调用shell
			
今天学习了Python通过子进程调用shell,感觉教程上讲的过于繁复,有一些根本没用的功能,比如重定向输入输出,这个shell本身就支持,没有必要用Python的api.决定自己总结下. 其实总的来 ...