Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 51503    Accepted Submission(s): 23178

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


Sample Output


题目大意与思路

输入一组数,n个,将该组数中相同数字的个数大于(n+1)/ 2 的数字输出。

我是看题目分类来做这个题的,怎么也想不出来动规怎么做 看了别人的题解恍然大悟 真是太高妙了

如果这个数出现次数大于(n+1)/ 2的话 那么他比所有其他的数出现次数都要多!

具体的看代码吧 应该很清楚了

#include<bits/stdc++.h>

using namespace std;

int i,n,cnt,anss,x;

int main()
{
while(scanf("%d",&n)!=EOF)
{
cnt=;
for(i=;i<=n;i++)
{
cin>>x;
if(cnt==)
{
cnt++;
anss=x;
}
else
{
if(x==anss)
cnt++;
else
cnt--;
}
}
cout<<anss<<endl;
}
}

HDU 1029 Ignatius and the Princess IV (动态规划、思维)的更多相关文章

  1. HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

  2. HDU 1029 Ignatius and the Princess IV --- 水题

    HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...

  3. HDU 1029 Ignatius and the Princess IV (map的使用)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: 2000/10 ...

  4. hdu 1029 Ignatius ans the Princess IV

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  5. [ACM] hdu 1029 Ignatius and the Princess IV (动归或hash)

    Ignatius and the Princess IV Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32767K (Ja ...

  6. HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)

    此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...

  7. HDU 1029 Ignatius and the Princess IV

    解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...

  8. HDU 1029 Ignatius and the Princess IV DP

    kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include< ...

  9. HDU 1029 Ignatius and the Princess IV(数论)

    #include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...

随机推荐

  1. qt5--鼠标操作

    #include "mylabel.h" #include <QDebug> #include <QPointF> #include <QPoint& ...

  2. qt5--数据类型转换

    QString-->Char*        str.toUtf8().data() pointf=QPointF(point);       //将QPoint转换为QPointF point ...

  3. vs 2019 调试web项目 浏览器

  4. CSS 内边距 padding 属性

    CSS padding 属性定义元素边框与元素内容之间的空白区域. ㈠padding(填充) ⑴当元素的 padding(填充)内边距被清除时,所释放的区域将会受到元素背景颜色的填充. ⑵单独使用 p ...

  5. poj 3685 Matrix 二分套二分 经典题型

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 5724   Accepted: 1606 Descriptio ...

  6. TTTTTTTTTT TTTTT CF 229C 三角形数量

    题意: 有一个无向完全图(任意两个节点之间均有一条边),包含 n(1<=n<=10^6) 个顶点,现在有两个人A 和 B,A从这个无向图中取出 m(0<=m<=10^6) 条边 ...

  7. 【UTR #3】量子破碎

    一道有趣的题. 看到按位的矩阵运算,如果对FWT比较熟悉的话,会比较容易地想到. 这种形式也就FWT等转移里面有吧--就算有其他的也难构造出来. 然而FWT的矩阵并不是酉矩阵(也就是满足 \(AA^T ...

  8. python实现的一个中文文本摘要程序

    文本摘要方法有很多,主要分为抽取式和生成式,应用比较多的是抽取式,也比较简单,就是从文本中抽取重要的句子或段落.本方法主要是利用句子中的关键词的距离,主要思想和参考来自阮一峰的网络日志http://w ...

  9. 【转】HDU-6035-Colorful Tree

    转自http://blog.csdn.net/Bahuia/article/details/76141574 题意: 题目链接:http://acm.hdu.edu.cn/showproblem.ph ...

  10. python中的实例方法、类方法、静态方法的区别

    Python 除了拥有实例方法外,还拥有静态方法和类方法,跟Java相比需要理解这个类方法的含义. class Foo(object): def test(self)://定义了实例方法 print( ...