博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1029——Ignatius and the Princess IV
阅读量:2344 次
发布时间:2019-05-10

本文共 1514 字,大约阅读时间需要 5 分钟。

Problem Description

“OK, you are not too bad, em… But you can never pass the next test.” feng5166 says.

“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?

Input

The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.

Output

For each test case, you have to output only one line which contains the special number you have found.

Sample Input

5
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1

Sample Output

3
5
1

题意是求序列中超过总个数一半的那个数是多少

正确的思路应该是:在原序列中,减去两个不同的数,剩下的序列中多一半的还是那个数。有一个0(n)的算法
但。。。。n的数据范围不大,可以直接暴力

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 110000#define Mod 10001using namespace std;int a[1000009];int main(){ int n,m,ans; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); for(int i=0;i

转载地址:http://ftcvb.baihongyu.com/

你可能感兴趣的文章
oracle性能监控
查看>>
Spring Boot 整合Servlet
查看>>
Spring Boot 整合Filter
查看>>
nginx 安装
查看>>
ngnix 详解
查看>>
IDEA创建spring boot项目
查看>>
IDEA安装插件
查看>>
HttpClient-02连接管理
查看>>
数据库连接池-配置 wallfilter问题解决-UncategorizedSQLException
查看>>
java根据文件流判断文件类型(后缀名)
查看>>
js常用操作事件
查看>>
linux 安装mysql
查看>>
利用SQL语句查询数据库中所有表
查看>>
ActiveMQ 安装
查看>>
java可变参数
查看>>
spring 简述
查看>>
HttpClient-03Http状态管理
查看>>
spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].
查看>>
常用软件下载地址
查看>>
修改spring boot 启动logo
查看>>