首页 > 其他 > 详细

HDU 1029 Ignatius and the Princess IV

时间:2017-03-20 18:39:41      阅读:296      评论:0      收藏:0      [点我收藏+]

 

技术分享

技术分享

题意:

出现超过n/2次的元素,是特殊的元素。

解题思路:

1. 在这个集合中每次删除两个不同的元素,那么剩下的最后一个元素,一定是特殊的元素。

2.把所有的元素排序,出现在n/2的元素,一定是特殊的元素

实现代码:

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 const int MAXN=10000000;
 6 
 7 int a[MAXN];
 8 
 9 int main(){
10     int n;
11     while(scanf("%d",&n)!=EOF){
12         for(int i=0;i<n;i++)
13             scanf("%d",&a[i]);
14         sort(a,a+n);
15         printf("%d\n",a[n/2]);
16 
17     }
18 }

 

HDU 1029 Ignatius and the Princess IV

原文:http://www.cnblogs.com/IKnowYou0/p/6590616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!