codeforces Winner
/*
* Winner.cpp
*
* Created on: 2013-10-13
* Author: wangzhu
*/ /**
* 先找出所有选手的分数和中最大的分数和,之后在所有选手的分数和中看有几个是和最大的分数和相等,
* 1)、若有多个,则比较谁在比赛结束钱分数先达到最大分数和,则是赢家;
* 2)、若只有一个,则直接输出。
*/
#include<cstdio>
#include<iostream>
#include<map>
#include<string.h>
using namespace std;
#define NMAX 1010
struct Node {
int index, val;
char name[];
};
Node node[NMAX];
map<string, int> myMap;
map<string, int> myMap1;
map<string, int>::iterator mapIterator; void find(int n, int nmax) {
int m;
for (int i = ; i < n; i++) {
for (mapIterator = myMap1.begin(); mapIterator != myMap1.end();
mapIterator++) {
if ( == strcmp(node[i].name, mapIterator->first.c_str())) {
// printf("%d %d %s\n", node[i].index, node[i].val, node[i].name);
m = myMap1[mapIterator->first];
m += node[i].val;
myMap1[mapIterator->first] = m;
if (m >= nmax) {
printf("%s\n", node[i].name);
return;
}
}
}
}
} int main() {
freopen("data.in", "r", stdin);
int n, m,nmax;
string nmaxStr;
while (~scanf("%d", &n)) {
myMap.clear();
myMap1.clear(); for (int i = ; i < n; i++) {
scanf("%s%d", node[i].name, &node[i].val);
node[i].index = i;
myMap[node[i].name] +=node[i].val;
}
nmax = -;
for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
if(nmax < mapIterator->second){
nmax = mapIterator->second;
}
}
m = ;
for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
if(nmax == mapIterator->second){
nmaxStr = mapIterator->first;
myMap1[mapIterator->first] = ;
m ++;
}
}
//printf("%d %d\n",m,nmax);
if(m != ){
find(n,nmax);
}else{
printf("%s\n",nmaxStr.c_str());
}
}
return ;
}
codeforces 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
Winner Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Codeforces Beta Round #2 A. Winner 水题
A. Winner 题目连接: http://www.codeforces.com/contest/2/problem/A Description The winner of the card gam ...
- Codeforces 2A :winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- 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 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 ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)
链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...
随机推荐
- asp.net中常用的几种身份验证方式
转载:http://www.cnblogs.com/dinglang/archive/2012/06/03/2532664.html 前言 在B/S系统开发中,经常需要使用"身份验证&q ...
- 12天学好C语言——记录我的C语言学习之路(Day 4)
12天学好C语言--记录我的C语言学习之路 Day 4: 首先来看一段程序: //输出下面4*5的矩阵 /* 1 2 3 4 5 2 4 6 8 10 3 6 9 12 ...
- @Transactional详解
@Transactional spring 事务注解 默认遇到throw new RuntimeException("...");会回滚需要捕获的throw new Exc ...
- 二维树状数组——SuperBrother打鼹鼠(Vijos1512)
树状数组(BIT)是一个查询和修改复杂度都为log(n)的数据结构,主要用于查询任意两位之间的所有元素之和,其编程简单,很容易被实现.而且可以很容易地扩展到二维.让我们来看一道很裸的二维树状数组题: ...
- JavaScript中的apply与call与arguments对象
(一) call方法 语法:presentObj.call(thisObj,arg1,arg2,arg3...) 参数thisObj :将被用作当前对象presentObj的对象. 当thisObj无 ...
- 11_Servlet基础知识
[概念] Servlet通常被称为服务端小程序,是运行在服务端的程序,用于处理及相应客户端的请求. Servlet是用java语言开发网页动态资源的技术. [特点] 1.Servlet是个特殊的Jav ...
- 错误:variable `xxx' has initializer but incomplete type
错误:variable `xxx' has initializer but incomplete type 原因:xxx对应的类型没有找到,只把xxx声明了但是没给出定义.编译器无从确认你调用的构造函 ...
- N的N次方(高校俱乐部)
最近一直在刷字符串和线段树,也越来越少玩高校俱乐部,无聊看到一题N的N次方的问题,脑海中各种打表就涌现出来了. 弄了不一会儿,就写完了,马上提交,但是系统好像出了问题,提示"哦哦,出了点状况 ...
- 实习笔记-2:sql 分组不一定要group by
今天在公司写代码的时候,遇到一个sql语句构建问题. 情形是这样的: 我需要获取不同小组下前N条记录. select top 10 * from dbo.Topic where GroupID in ...
- RX学习笔记:Bootstrap
Bootstrap https://getbootstrap.com 2016-07-01 在学习FreeCodeCamp课程中了解到Bootstrap,并于课程第一个实战题卡在响应式部分,于是先对B ...