Codeforces Beta Round #2 A. Winner

果然水到家了,自从回来开始连一道CF的A都做不出来,交了10次WA也是醉了。


题目大意:

给出n个操作,每个操作是某个名字加多少分。求最后谁是第一名。

第一名的定义是:获得分数最高。如果有多个分数最高,谁最先达到这个分数的就是谁。

每个人的基础分是0.



下面是代码:

#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <cctype>
#include <algorithm>

#define eps 1e-10
#define pi acos(-1.0)
#define inf 107374182
#define inf64 1152921504606846976
#define lc l,m,tr<<1
#define rc m + 1,r,tr<<1|1
#define zero(a) fabs(a)<eps
#define iabs(x)  ((x) > 0 ? (x) : -(x))
#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))
#define clearall(A, X) memset(A, X, sizeof(A))
#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))
#define memcopyall(A, X) memcpy(A , X ,sizeof(X))
#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )

using namespace std;

struct node
{
    string str;
    int t;
}node1[1005];

int main()
{
    int n;
    scanf("%d",&n);
    map <string ,int> map1;
    for(int i=0;i<n;i++)
    {
        cin>>node1[i].str>>node1[i].t;
        map1[node1[i].str]+=node1[i].t;
    }
    map<string,int >::iterator it=map1.begin();
    int max1=it->second;
    while(it!=map1.end())
    {
        max1=max(max1,it->second);
        it++;
    }
    map<string ,int>map2;
    map1.clear();
    for(int i=0;i<n;i++)
    {
        map1[node1[i].str]+=node1[i].t;
        if(map1[node1[i].str]>=max1&&map2.find(node1[i].str)==map2.end())
        {
            map2[node1[i].str]=i;
        }
    }
    int maxt=10000000;
    string maxname;
    for(it=map1.begin();it!=map1.end();it++)
    {
        if(it->second>=max1&&map2[it->first]<maxt)
        {
            maxname=it->first;
            maxt=map2[it->first];
        }
    }
    cout<<maxname;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值