[kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV
来源:互联网 发布:纹身设计软件在线 编辑:程序博客网 时间:2024/06/05 05:56
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 25818 Accepted Submission(s): 10905
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?
"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
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
Sample Output
#include <cstdio>#include <algorithm>#include <iostream>using namespace std;typedef long long ll;int main(void){int number;while (~scanf("%d", &number)){int temp, cnt, ans;cnt = 0;while (number--){scanf("%d", &temp);if (cnt == 0){ans = temp;cnt = 1;}if (ans == temp) cnt++;else cnt--;}cout << ans << endl;}}
351
分析:对于出现次数大于(1+n)/2的数,显然有如下代码
code:
0 0
- [kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV
- [kuangbin带你飞]专题十二 基础DP1 -B
- 【 题集 】 【kuangbin带你飞】专题十二 基础DP1
- kuangbin带你飞 专题十二 基础DP1
- [kuangbin带你飞]专题十二 基础DP1 O POJ3186
- [kuangbin带你飞]专题十二 基础DP1
- [kuangbin带你飞]专题十二 基础DP1
- [kuangbin带你飞]专题十二 基础DP1 C
- [kuangbin带你飞]专题十二 基础dp1
- [kuangbin带你飞]专题十二 基础DP1
- [kuangbin带你飞]专题十二 基础DP1 B HDU 1029
- kuangbin求带飞DP1 Ignatius and the Princess IV( 漂亮的解法!!)
- [kuangbin带你飞]专题十二 基础DP1 G - 免费馅饼(HDU 1176)
- [kuangbin带你飞]专题十二 基础DP1 G - 免费馅饼
- [kuangbin带你飞]专题十二 基础DP1 I - 最少拦截系统
- [kuangbin带你飞]专题十二 基础DP1 A HDU 1024
- [kuangbin带你飞]专题十二 基础DP1 C HDU 1069
- [kuangbin带你飞]专题十二 基础DP1 D HDU 1074
- 当装了dreamweaver等某些IDE时,css失效了,其中1个原因
- dfafdsa
- 使用jni计算两个数字的结果
- 关于ArrayList的5道面试题
- 关系型数据库与HBase的数据储存方式区别
- [kuangbin带你飞]专题十二 基础DP1 B - Ignatius and the Princess IV
- Android framework修改----Android原生字体,连体字效果
- keil编译出现function abs declared implicitly的解决方法
- 转载:林仕鼎: 系统架构领域的一些学习材料
- Lightoj1038 概率dp + 因数分解
- iOS开发经验总结(上)
- 237DeleteNodeinaLinkedList
- make: 没有什么可以做的为 `all'。
- C++第五次实验(数组分离)