URAL 1510. Order(map 数学啊)

题目链接: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;
}
时间: 2024-11-02 23:39:38

URAL 1510. Order(map 数学啊)的相关文章

CodeForces 567C. Geometric Progression(map 数学啊)

题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp loves geometric progressions very much. Since he was on

URAL 2003. Simple Magic(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2003 2003. Simple Magic Time limit: 1.0 second Memory limit: 64 MB Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is enough to conjure wonderful garden

URAL 1515. Cashmaster (数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1515 Background Once upon a time former petty bureaucrat, nowadays the Minister of Finance of the Soviet Federation, Victor Thiefton considered, that he had stolen so much money during the first half

URAL 2047 Maths (数学)

对于一个数来说,它的除数是确定的,那么它的前驱也是确定的,而起点只能是1或2,所以只要类似筛法先预处理出每个数的除数个数 ,然后递推出每个数往前的延伸的链长,更新最大长度,记录对应数字.找到maxn以后,根据最后一个数找到前驱,并记录到ans数组中. 代码来自队友 #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<vector> #

URAL 1731. Dill(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1731 1731. Dill Time limit: 0.5 second Memory limit: 64 MB Ivan Vasil'evich likes to work in his garden. Once he heard that dill was a very beautiful and healthy crop and planted his whole garden with

URAL 1718 . Rejudge(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1718 1718. Rejudge Time limit: 0.5 second Memory limit: 64 MB At three o'clock in the morning Sasha (aka Sandro) discovered that there were only seven tests for one of the problems in the first volume

URAL 1295 Crazy Notions 数学 找规律

1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of the atmospheric electricity has led to the depressurizati

URAL 1823. Ideal Gas 数学,分类

1823. Ideal Gas Time limit: 0.5 second Memory limit: 64 MB Many of you know the universal method of solving simple physics problems: you have to find in a textbook an identity in which you know the values of all the quantities except for one, substit

URAL 1826. Minefield(数学啊 递归)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1826 1826. Minefield Time limit: 0.5 second Memory limit: 64 MB To fulfill an assignment, a reconnaissance group of n people must cross the enemy's minefield. Since the group has only one mine detecto