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 ...
随机推荐
- Set和Map集合的比较
HashSet:数据进行hashCode比较,然后进行equals方法比较,根据比较结果进行排序.如果要对对象进行排序,对象类要重写hashCode和equals方法.TreeSet:如果要对对象进 ...
- python绘制疫情图
python中进行图表绘制的库主要有两个:matplotlib 和 pyecharts, 相比较而言: matplotlib中提供了BaseMap可以用于地图的绘制,但是个人觉得其绘制的地图不太美观, ...
- [Qt5] 使用Qt设计器绘制主窗口
实践代码: git clone https://github.com/dilexliu/learn_qt5.git Step1: Qt设计器绘制窗口 保存会得到一个文件: mainwindow.ui ...
- Tomcat的部署、虚拟主机及优化
Tomcat的部署.虚拟主机及优化 文章目录 Tomcat的部署.虚拟主机及优化 前言 1.Tomcat的名称由来 2.Apache Tomcat 5-7版本差异 2.1Apache Tomcat5. ...
- System.Diagnostics.Conditional 的妙用 -- 把文档放在代码中
最近的工作跟 UI 打交道比较多, 各种坑. 今天从 Prefab 的序列化功能来说说 System.Diagnostics.Conditional 的妙用. 我们做 UI 面对各种按钮, 组件的获取 ...
- UGUI 特效怎样在UI上裁剪
刚好碰到有人问怎样把粒子特效放到 UI 上并且能正确被 Mask 裁剪, 首先想到给粒子效果的 Shader 添加模板模仿一般 UI 的模板方式, 应该就能正确裁剪了吧, 不过没那么简单, 我们看到在 ...
- [转]ubuntu备份与恢复
在 使用Ubuntu之前,相信很多人都有过使用Windows系统的经历.如果你备份过Windows系统,那么你一定记忆犹新:首先需要找到一个备份工 具(通常都是私有软件),然后重启电脑进入备份工具提供 ...
- 1-Docker学习笔记
docker还是比较容易的,比较蛋疼的就是镜像网络问题,不过也可以配置了镜像加速器(比如阿里云).这里重点记录一下初学docker时遇到的知识点. docker环境变量 docker对环境变量的定义和 ...
- 十五 链表与递归,leetCode203题
两种方式: package com.lt.datastructure.LinkedList; /** * leetCode 203题 * /** * Definition for singly-lin ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:表示一个危险动作的按钮操作
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...