Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 27227 Accepted Submission(s): 11562
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
"But what is the characteristic of the special integer?" Ignatius asks.
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.
Can you find the special integer for Ignatius?
#include<iostream> #include<stdio.h> #include<map> using namespace std; map <int,int> num; int main() { int n; while(~scanf("%d",&n)) { num.clear(); for(int i=0;i<n;i++) { int tmp; scanf("%d",&tmp); num[tmp]++; } int times= (n+1)/2; int ans= 0x3ffffff; map<int,int>::iterator iter; for(iter=num.begin();iter!=num.end();iter++) { if(iter->second>=times) ans= iter->first; } printf("%d\n",ans); } }