HDU 1029 Ignatius and the Princess IV (动态规划、思维)
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
"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
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
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 (动态规划、思维)的更多相关文章
- 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 ...
- HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
- 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 ...
- hdu 1029 Ignatius ans the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- [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 ...
- HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...
- HDU 1029 Ignatius and the Princess IV
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
- HDU 1029 Ignatius and the Princess IV DP
kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include< ...
- HDU 1029 Ignatius and the Princess IV(数论)
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...
随机推荐
- Python的语句---钱中平
python中的两种语句:1.if条件控制语句 格式: if: a = int(input("请输入第一个数:"))b = int(input("请输入第二个数:&quo ...
- Eclipse中SVN分支与合并
一.创建分支 Eclipse中利用svn插件创建分支,如下图 分支创建完毕,查看svn资源库中可以看到,分支信息: 二.分支合并主干 1.切换到分支,如图 切换: 2.修改分支信息 在pojo中新增T ...
- 有时间看看这个方法 会不会 避免 xss
Server.HtmlEncode 能将字符串原样输出 包括html标签
- mysql 递归查找所有子节点
select dept_id from ( select t1.dept_id,t1.parent_id, if(find_in_set(parent_id, @pids) > 0, @pids ...
- jquery pageX属性 语法
jquery pageX属性 语法 作用:pageX() 属性是鼠标指针的位置,相对于文档的左边缘. 语法:event.page 参数: 参数 描述 event 必需.规定要使用的事件.这个 ...
- Java基础-自增自减运算符练习题
我们用一个简单的例子分析下边的运行结果: package demo; public class ZiZeng { int i = 0; test(i); // i = i++; i = ++i; Sy ...
- Java多线程和并发(十),JMM(Java内存模型)
目录 1.什么是JMM 2.JMM的主内存和工作内存 3.JMM如何解决可见性问题-指令重排序 4.Volatile 十.JMM(Java内存模型)(暂时没有理解) 1.什么是JMM 2.JMM的主内 ...
- Miller Rabin 算法简介
0.1 一些闲话 最近一次更新是在2019年11月12日.之前的文章有很多问题:当我把我的代码交到LOJ上,发现只有60多分.我调了一个晚上,尝试用{2, 3, 5, 7, 11, 13, 17, 1 ...
- 深度学习笔记(十)Augmentation for small object detection(翻译)
一. abstract 这些年来,目标检测取得了令人瞩目的成就.尽管改进很大,但对于小目标和大目标的检测性能差异还是蛮大的.我们在 MS COCO 数据集上分析了如今一个比较先进的算法,Mask-RC ...
- mystrcat
#include<stdio.h> //如果一个数组做为函数的形参传递,那么数组可以在被调用的函数中修改 //有时候不希望这个事发生,所以对形参采用const参数 //size_t str ...