Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d & %I64u
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
Output
Sample Input
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
5
1
/*
题意:给你奇数个数,然后让你找出一个数,这个数在里面至少出现过(n+1)/2次 初步思路:感觉可以暴力搞一下
*/
#include <bits/stdc++.h>
using namespace std;
int n;
int a;
int vis[];
void init(){
memset(vis,,sizeof vis);
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
int res=;
for(int i=;i<n;i++){
scanf("%d",&a);
vis[a]++;
if(vis[a]>=(n+)/)
res=a;
}
printf("%d\n",res);
}
return ;
}
Ignatius and the Princess IV(乱搞一发竟然过了)的更多相关文章
-
hdu 1029 Ignatius ans the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
-
HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
-
Ignatius and the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
-
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 ...
-
(Arrays.sort() 或 map) Ignatius and the Princess IV hdu1029
Ignatius and the Princess IV 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 借鉴链接:https://blog.csd ...
-
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 ...
-
HDOJ.1029 Ignatius and the Princess IV(map)
Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...
-
kuangbin专题十二 HDU1029 Ignatius and 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 ...
随机推荐
-
Android中有关relativeLayout 和EditText的一些属性
http://www.cnblogs.com/jqyp/archive/2010/10/23/1859182.html RelativeLayout用到的一些重要的属性: 第一类:属性值为true ...
-
252.	Meeting Rooms
题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
-
Android Handler与多线程
本文首先解释一下handler是用来干嘛的,然后通过例子介绍其在多线程中的应用. 什么是Handler handler通俗一点讲就是用来在各个进程之间发送数据的处理对象.在任何进程中,只要获得了另一个 ...
-
C#打印100以内质数
bool b = false; ; i < ; i++) { ; j < i; j++) { ) { b = false; break; } else { b = true; } } if ...
-
ezw证件照芯片压缩算法
相关网站:http://m.blog.csdn.net/blog/kimwu/12654517 http://blog.sina.com.cn/s/blog_4be751690100bsgb.html ...
-
转:Java中finally和return的执行关系
finally可以分两方面理解 1.执行时机问题.finally总会执行(除非是System.exit()),正常情况下在try后执行,抛异常时在catche后面执行 2.返回值问题.可以认为try( ...
-
关闭VS警告 warning C4996
warning C4996: '_vsnprintf': This function or variable may be unsafe. ...... warning C4996: strcpy w ...
-
SD
Offer(Tcode:VA23;Table: vbak and vbap) billing(Tcode:VF03;Table:vbrk and vbrp) Offer(quotation)-> ...
-
postgres(pgAdmin) 客户端保存密码
pgAdmin 大象客户端保存密码后连接服务器,删除掉当前连接,建立一个新的连接不用输入密码也能连接上,其实是客户端保存了密码,让人误以为是空密码可登录.可以通过右键连接,选择重载服务配置,再次连接就 ...
-
怎么打乱List中元素的顺序
使用Collections类中shuffle随机打乱List内部元素顺序 原文地址:http://blog.csdn.net/warren2013/article/details/17414771 / ...