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. C# webapi

    HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统cont ...

  2. 什么是弹性盒子 ( Flex Box)?

    ㈠什么是弹性盒子? 弹性盒子是 CSS3 的一种新的布局模式.引入弹性盒布局模型的目的是提供一种更加有效的方式来对一个容器中的子元素进行排列.对齐和分配空白空间. 弹性盒子由弹性容器(Flex con ...

  3. File类、FileInfo类、Directory类、DirectoryInfo类

    File类.Directory类,都是静态类,可以直接使用类名 FileInfo类.DirectoryInfo类,都是动态类,需要new对象,通过对象来操作 [文件的创建.复制.移动.删除]using ...

  4. React-native 环境配置及项目创建

    https://reactnative.cn/docs/next/getting-started.html 看到  安装 Android Studio 安装 Android Studio http:/ ...

  5. Vue成员与指令介绍

    一.Vue介绍 1.什么是vue 通过对框架的了解与运用程度,来决定其在整个项目中的应用范围, 可以独立完成前后端分离式web项目的渐进式JavaScript框架 2.为什么要学vue 三大主流框架之 ...

  6. [清华集训2016]温暖会指引我们前行——LCT+最大生成树

    题目链接: [清华集训2016]温暖会指引我们前行 题目大意:有$n$个点$m$次操作,每次操作分为三种:1.在$u,v$两点之间连接一条编号为$id$,长度为$l$,温度为$t$的边.2.查询从$u ...

  7. IDEA的Python工程在inspections时提示:The JDK is not configured properly for this project. Inspection cannot proceed.

    原因:IDEA将工程误认为了Java工程. 解决方法:如果确认这是个Python工程,修改*.iml文件,将下面的这一行删除 <orderEntry type="inheritedJd ...

  8. 安卓项目集成objectbox-java数据库框架教程(非关系型)

    objectbox数据库是greenrobot团队开发的全新非关系型数据库框架,该团队还开发过greenDao,EventBus等热门框架,objectbox可能是第一次听说,但是greenDao,E ...

  9. C++入门经典-例2.9-输出十六进制数以及大写的十六进制数

    1:代码如下: #include "stdafx.h" #include <iostream> #include <iomanip> using names ...

  10. 使用ffmpeg切片出hls

    测试的时候经常要用到ffmpeg切hls的流 ffmpeg -re -i g:/media/baifa.mp4 -codec copy -f hls -hls_list_size -hls_wrap ...