题目链接:http://codeforces.com/problemset/problem/2/A
题目描述:

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.

输入输出样例:

题解:

题目意思:要求 求出得分最大的名字,如果有多个得分最大的名字,那么输出在这些名字中,在游戏过程中最先到达该最大得分的名字。(注意:不是在游戏完成后,只要在游戏过程中到达过该最大得分就可以。但这些名字对应的分数一定在游戏结束后是最大的).
题解:确定数据存储结构,一个结构体用来输入(这样可以同时用 i 记录得分顺序),两个map,m 是第一遍存储分数,用来得到整个游戏结束后的最大值;t 是第二遍存储分数,用来存储,在游戏过程中的分数。因此,只需要找到 t[name] 大于等于最大分数,并且m[name] == 最大值的那个位置即可,也就是:if (t[a[i].str] >= maxn && m[a[i].str] == maxn)

参考代码:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;#define MAX_NUM 200005
#define INF 0x3f3f3f
#define ll long long
#define clean(arrays) memset(arrays, 0, sizeof(arrays))struct score
{string str;int s;
}a[1005];
int n, s;
map<string, int> m, t;
string str;int main()
{cin>>n;for (int i = 1; i <= n; i++){cin>>a[i].str>>a[i].s;m[a[i].str] += a[i].s;      //记录每个人的总分}int maxn = -INF;for (int i = 1; i <= n; i++){if (m[a[i].str] > maxn)maxn = m[a[i].str];}   //找出游戏结束时的最大值int minn = INF;for (int i = 1; i <= n; i++){t[a[i].str] += a[i].s;if (t[a[i].str] >= maxn && m[a[i].str] == maxn){    //找到等于最大值的人中,谁先到达最大值minn = i;break;}}cout<<a[minn].str<<endl;return 0;
}

Codeforces Beta Round #2-A. Winner——算法笔记相关推荐

  1. Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)

    Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...

  2. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  3. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新

    http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...

  4. Codeforces Beta Round #51 D. Beautiful numbers 数位dp + 状态优化

    传送门 文章目录 题意: 思路: 题意: 思路: 数位dpdpdp挺经典的一个题辣,有一个很明显的状态就是f[pos][num][lcm]f[pos][num][lcm]f[pos][num][lcm ...

  5. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)

    题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...

  6. codeforces beta round 1

    codeforces beta round 1 A Theatre Square in the capital city of Berland has a rectangular shape with ...

  7. Codeforces Beta Round #4 (Div. 2 Only)

    Codeforces Beta Round #4 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 ...

  8. Codeforces Beta Round #7

    Codeforces Beta Round #7 http://codeforces.com/contest/7 A 水题 1 #include<bits/stdc++.h> 2 usin ...

  9. Codeforces Beta Round #1 A,B,C

    A. Theatre Square time limit per test:1 second memory limit per test:256 megabytes input:standard in ...

最新文章

  1. uboot学习之BL3的流程
  2. 大华监控服务器显示感叹号灯亮,仪表盘出现黄色感叹号灯亮什么问题
  3. oracle11g创建表空间大文件,oracle11g创建表空间 sql语法
  4. RocketMQ如何保证消息不丢失? 如何快速处理积压消息?
  5. 一个cmake的简单例子:来自github
  6. django settings 定义的变量不存在_Django基础框架搭建
  7. 三维重建——使用colmap进行重建
  8. hdu 4334 Trouble 排序+优化 多校联合赛(四)第四题
  9. bzoj2958: 序列染色3269: 序列染色
  10. Python一元二次方程求根
  11. Django 搭建知乎热榜 API
  12. jquery更新后怎样在一个站点中使用两个版本号的jQuery
  13. rl滤波器原理_滤波器的基础知识
  14. 小米8透明探索版无限重启,且有BootLoader锁的情况下卡刷机成功
  15. 不让玩游戏的小娃娃随机考试系统
  16. OPC教程三:KEPServerEX6的使用
  17. python正则表达式(关于提取数字)
  18. C语言.h文件的作用
  19. XSS Challenges
  20. NumPy 和 Pandas 数据分析实用指南:1~6 全

热门文章

  1. 修改docker默认存储位置
  2. 班主任请收下!成绩统计必不可少的一波Excel技巧
  3. 使用jeecg-boot心得
  4. autoCAD2002-2022安装教程
  5. 上海宝付带你看:近期电信诈骗警情分析及典型案例
  6. 小i机器人袁辉在亚洲金融论坛谈创业创新与亚洲AI市场
  7. Flutter 2020 开源项目推荐 第一弹
  8. ceaspectusG超级智能闸口,革新科技箱况残损检测,识别率99.95%,全自动化进出闸,应用智慧港口码头,智慧无人堆场
  9. 【HCIE】NO.45 Hub and Spoke配置案例
  10. Python 获取图片上点的坐标