码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1510. Order(map 数学啊)

时间:2015-03-28 11:38:09      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:ural   数学   stl   

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1510


1510. Order

Time limit: 1.0 second
Memory limit: 16 MB
A New Russian Kolyan likes two things: money and order. Kolyan has lots of money, but there is no order in it. One beautiful morning Kolyan understood that he couldn‘t stand this any longer and decided to establish order in his money. He told his faithful mates to fetch the money from an underground depository, and soon his big room was filled up with red, green, and blue banknotes. Kolyan looked with disgust at this terrible mess. Now he wants to leave in his depository only banknotes of the same value and to give the rest of the money to the poor. He knows exactly that more than half banknotes have the same value. But in this mess it is impossible to understand which banknote is the most common.

Input

The first line contains the number of Kolyan‘s banknotes N (1 ≤ N ≤ 500000). In the next N lines, the values K of these banknotes are given (0 ≤ K ≤ 109). More than half of them are the same.

Output

Output the most common value.

Sample

input output
5
3
3
2
2
3
3
题意:

Output the most common value.

看最后一句就知道拉!

注意:G++超时,用C++交!

代码如下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
map<int,int >a;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int tt;
        int maxx = 0;
        int ans = -1;
        for(int i = 0; i < n; i++)
        {
            scanf("%d",&tt);
            a[tt]++;
            if(a[tt] > maxx)
            {
                ans = tt;
                maxx = a[tt];
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


URAL 1510. Order(map 数学啊)

标签:ural   数学   stl   

原文地址:http://blog.csdn.net/u012860063/article/details/44699337

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!