hdu 1029 Ignatius and the Princess IV
2015-06-20 14:51
501 查看
题意:找出出现次数大于(N+1)/2的数。
思路:开一个一维数组dp[ 100 0000 ] --- 数组的序号与数出现的次数匹配
例如:
5
1 2 1 1 7
dp[1] = 3;
dp[2]= 1;
dp[7] = 1;
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 20766 Accepted Submission(s): 8574
Problem Description
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.
”好吧,你不是太糟糕了,他们……但你永远不能通过接下来的考试。“ feng5166说。
"I will tell you an odd number N, and then N integers. There will be a special integer among them,
“ 我将告诉你一个奇数N,然后N个整数。在N个数之间有一个特殊的整数,
you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
你的目标是找出这个整数的位置。” feng5166说。
"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.
”这个整数至少出现 (N+1)/2次。如果你找不到这个整数,我就杀死公主,你也会成为我的晚餐。哈哈。。。“ feng5166说。
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.
接着 第二行有N个数。当输入数据到达文件末尾是,表示输入结束。
Output
For each test case, you have to output only one line which contains the special number you have found.
对于每一个测试用例,在单独的一行输出这个特别的数。
Sample Input
Sample Output
Author
Ignatius.L
思路:开一个一维数组dp[ 100 0000 ] --- 数组的序号与数出现的次数匹配
例如:
5
1 2 1 1 7
dp[1] = 3;
dp[2]= 1;
dp[7] = 1;
#include<stdio.h> int dp[1000000];//100万,初始化为0 int main(){ int n=0,temp = 0,i,yes; while(scanf("%d",&n)!=EOF){ //初始化 for(i=0;i<1000000;i++){ dp[i]=0; } for(i=0;i<n;i++){ scanf("%d",&temp); dp[temp]++; if(dp[temp]>=(n+1)/2){ yes=temp;//标记 } } printf("%d\n",yes); } return 0; }
Ignatius and the Princess IV
伊格内修斯和四公主Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 20766 Accepted Submission(s): 8574
Problem Description
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.
”好吧,你不是太糟糕了,他们……但你永远不能通过接下来的考试。“ feng5166说。
"I will tell you an odd number N, and then N integers. There will be a special integer among them,
“ 我将告诉你一个奇数N,然后N个整数。在N个数之间有一个特殊的整数,
you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
你的目标是找出这个整数的位置。” feng5166说。
"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.
”这个整数至少出现 (N+1)/2次。如果你找不到这个整数,我就杀死公主,你也会成为我的晚餐。哈哈。。。“ feng5166说。
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.
接着 第二行有N个数。当输入数据到达文件末尾是,表示输入结束。
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
Author
Ignatius.L
相关文章推荐
- activemq安装和启动
- win10系统开机蓝屏 代码电脑蓝屏错误0x00000001e怎么办?
- Python strange questions list
- 学历iOS开发纪录(结构体和数组指针)
- 递归加载目录
- 好好看代码,天天敲代码
- DZ论坛的登录POST数据分析
- SpringMVC傻瓜式教程搭建
- C语言的一些简单操作
- MySQL数据库远程连接开启方法
- 显示文件夹下所有图片
- eclipse仿VS2013皮肤
- 单机访问samba
- 佛学大师智慧(3)
- python正则表达式
- C#语法之{0:C}及其扩展
- hdu 5247 找连续数(灵活,超时题)
- C#面向对象设计模式纵横谈4 Builder生成器模式创建型模式
- windows下如何远程连接Linux电脑
- Backpropagation Algorithm记录