hdu1029Ignatius and the Princess IV

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029

好像用不着动态规划。。。

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 const int maxn=1000010;
 5 int dp[maxn];
 6 int p[maxn];
 7 
 8 int main()
 9 {
10     int n;
11     while(scanf("%d",&n)!=EOF)
12     {
13         int m=(n+1)/2;
14         int ansm=1,ansi;
15         for(int i=0;i<n;i++)
16         scanf("%d",&p[i]);
17             sort(p,p+n);
18         for(int i=1;i<n;i++)
19         {
20             if(p[i]==p[i-1]) {ansm++; if(ansm>=m) {ansi=p[i];break;}}
21             else ansm=1;
22         }
23         printf("%d\n",ansi);
24     }
25 }

 

posted @ 2017-03-22 20:06  yijiull  阅读(95)  评论(0编辑  收藏  举报