HDU 1029 Ignatius and the Princess IV

参考:https://blog.csdn.net/chudongfang2015/article/details/51378036

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 const int N=1e6+10;
 7 int a[N];
 8 int main()
 9 {
10     int n;
11     while (cin>>n)
12     {
13         for (int i=0;i<n;i++)
14         {
15             cin>>a[i];
16         }
17         sort(a,a+n);
18         int flag=(n+1)/2,f=1;
19         for (int i=0;i<n;i++)
20         {
21             if (a[i]=a[i+1])
22             {
23                 f++;
24                 if (f>=flag)
25                 {
26                     cout<<a[i]<<endl;
27                     break;
28                 }
29             }
30             else
31             {
32                 f=1;
33             }
34         }
35     }
36 
37     return 0;
38 }

 

posted @ 2018-08-08 18:07  hemeiwolong  阅读(83)  评论(0编辑  收藏  举报