zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    如何提高Android代码的安全性
    Android数据库安全解决方案,使用SQLCipher进行加解密
    【Android UI设计与开发】第16期:滑动菜单栏(一)
    4种必须知道的Android屏幕自适应解决方案
    android权限大全
    在Windows7下构建Android的开发环境
    Android 悬浮歌词(迷你歌词)效果解读 (转)
    大数据量数据库优化(转)
    使用isInEditMode解决可视化编辑器无法识别自定义控件的问题(转)
    导入开源项目后报:Caused by: java.lang.ClassNotFoundException: Didn't find class
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5262919.html
Copyright © 2011-2022 走看看