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+ ...
随机推荐
- Python学习笔记 - day13 - 进程与线程
概述 我们都知道windows是支持多任务的操作系统. 什么叫“多任务”呢?简单地说,就是操作系统可以同时运行多个任务.打个比方,你一边在用浏览器上网,一边在听MP3,一边在用Word赶作业,这就是多 ...
- Python3 hashlib模块和hmac 模块(加密)
hashlib 是一个提供了一些流行的hash算法的 Python 标准库.其中所包括的算法有 md5, sha1, sha224, sha256, sha384, sha512等常用算法 MD5加密 ...
- Leetcode 之Flatten Binary Tree to Linked List(50)
将左子树接到右子树之前,递归解决 void flatten(TreeNode *root) { if (root == nullptr)return; flatten(root->left); ...
- Nginx web proxy NFS服务
1.nginx web 安装 配置 #systemctl stop firewalld #systemctl disabled firewalld #wget -O /etc/yum.repos.d/ ...
- JVM字节码执行引擎和动态绑定原理
1.执行引擎 所有Java虚拟机的执行引擎都是一致的: 输入的是字节码文件,处理过程就是解析过程,最后输出执行结果. 在整个过程不同的数据在不同的结构中进行处理. 2.栈帧 jvm进行方法调用和方法执 ...
- python 单例模式4中实现方法
python实现单例模式的方法: 1. 使用模块 python的模块在第一次导入时会生成.pyc文件,当第二次导入时就会直接加载.pyc文件,而不会再次执行模块代码. 只需将其单独放在一个模块里,并创 ...
- 走进 Akka.NET
官方文档:https://getakka.net/index.html 官网:https://petabridge.com/ 一.Akka.NET 是什么? Akka 是一个构建高并发.分布式和弹性消 ...
- 是时候升级你的Js工具了-分页【基于JQ】
好久没有来逛园子,也好久没有更新博客,就像沉睡已久的人忽然被叫醒,忽然就被园友的回复惊醒了.园友提出了关于我之前一篇文章的疑问——可那已经是半年以前的博客了,加上我一直觉得分享给大家的应该是我最新的思 ...
- Kbengine cocos2djs 地图问题
KBEngine.addSpaceGeometryMapping(self.spaceID, None, resPath) 问下这个resPath加载的文件在哪里,后端愣是没找到,前端倒是看到了,还是 ...
- vue-music 关于playlist (底部播放列表组件)
建立playlist.vue 组件,在player.vue 组件中引用,点击迷你播放器的播放列表按钮由下至上弹出这个层,所以在player.vue 播放器组件中引用 在playlist.vue 组件中 ...