您的位置:首页 > 其它

ZCMU-1773-Mode

2017-01-02 13:07 204 查看

1773: Mode

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 77  Solved: 28

[Submit][Status][Web
Board]

Description

Give you a number of n series, in which a number of more than n / 2 times , you should find out that the number (n<=500000,x<=10^19)

Input

The first line is a positive integer n. The second line of n positive integers separated by spaces.

Output

A Positive integer on a line indicates that number 

Sample Input

5

3 2 3 1 3

Sample Output

3

【解析】

题目大意,给你一个序列叫你输出出现序列的次数超过n/2次的数,每输出一个换行,看到这么大的数据我直接用map

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
map<long long,int>a;
int main()
{
int n;
long long p;
while(~scanf("%d",&n))
{
a.clear();
for(int i=0;i<n;i++)
{
scanf("%lld",&p);
if(a[p]!=-1)
a[p]+=1;
if(a[p]>n/2)
{
printf("%lld\n",p);
a[p]=-1;
}
}
}
return 0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: