[HDU1029]Ignatius and the Princess IV<桶 水题>
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029
题目大意:
多组数据,每组数据先给一个n,然后给n各数字,找出n各数字中出现了至少(n+1)/2次的数字并输出(保证n为奇数)
看到这题被分类进了dp我还是有点懵逼,我不知道我这算不算dp做法。
我是用的桶排序思想,
由于数据范围如此,直接进行遍历桶是会炸时间的,
所以多开一个数组记录下出现过的数字就行。
题不难
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} int barrel[],n,have[],tot; int main(){
while(scanf("%d",&n)!=EOF){
tot=;memset(barrel,,sizeof(barrel));
for(int i=;i<=n;i++){
int a=read();
if(barrel[a]==)have[++tot]=a;
barrel[a]++;
}
int num=(n+)/;
for(int i=;i<=tot;i++)
if(barrel[have[i]]>=num){
cout<<have[i]<<endl;break;
}
}
return ;
}
[HDU1029]Ignatius and the Princess IV<桶 水题>的更多相关文章
- kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- HDU1029 - Ignatius and the Princess IV【水题】
给你n个数字,请你找出出现至少(n+1)/2次的数字. 输入 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行 ...
- 【HDU - 1029】Ignatius and the Princess IV (水题)
Ignatius and the Princess IV 先搬中文 Descriptions: 给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...
- Ignatius and the Princess IV (水题)
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says. &qu ...
- HDU1029 Ignatius and the Princess IV (水题)
<题目链接> 题目大意:给你一段序列,问你在这个序列中出现次数至少为 (n+1)/2 的数是哪个. 解题分析: 本题是一道水题,如果用map来做的话,就非常简单,但是另一个做法还比较巧妙. ...
- 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(也可以用数组)记录每个数出 ...
- (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 ans the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
随机推荐
- Linux中软连接和硬连接的区别
首先,我们要清楚符号链接的目的,在不改变原目录/文件的前提下,起一个方便的别名(在这起个别名,让我想到前阶段学C里typedef也是起别名的). 1.软连接就相当于windows的快捷方式.例如:ln ...
- JAVA有关位运算的全套梳理
一.在计算机中数据是如何进行计算的? 1.1:java中的byte型数据取值范围 我们最开始学习java的时候知道,byte类型的数据占了8个bit位,每个位上或0或1,左边第一位表示符号位,符号位如 ...
- 本地目录配置多个远程Git仓库
目录 情景一:不同的库分别 pull/push 1. 使用git命令配置 2. 修改.git/config 文件 3. 操作 情景二:不同的库一次push 1. 使用git命令配置 2. 修改.git ...
- Lambda 方法引用
1.方法引用:若Lambda 体中的内容有方法已经实现了,我们可以使用“引用方法”(可以理解为方法引用是Lambda表达式的另外一种表现形式) 方法引用主要有三种语法格式: ① 对象 :: 实例方法 ...
- 304 Not Modified
304 Not Modified,不是服务器发出的错误,是服务器所承载的业务系统在开发时为了节省带宽和提升浏览器的体验,对GET/js,css,image等执行了缓存机制.客户端第一次对服务器发出GE ...
- 使用Navicat Premiun远程连接MySQL失败,报错(10038)
远程连接MySQL失败,可能有一下原因: 1.小伙子/小姑凉注意一下你的ip是否输入正确了!! 2.网络或防火墙问题 1).排查网络问题 使用命令:ping 192.168.1.1 查看网络请求是否超 ...
- arm 添加 samb 文件共享
编译环境: ubunto 12 arm-linux-gcc 4.3.2 arm linux 4.1.36 开发板 2440 测试上传速度,大文件 github源码 https://github.com ...
- selenium+Python 将登录模块化
公共模块化:(登录) login.py from selenium import webdriver from time import sleep class login(): def u ...
- python enumerate用法总结(转)
原文链接:https://blog.csdn.net/churximi/article/details/51648388 enumerate()说明 enumerate()是python的内置函数en ...
- [BJDCTF 2nd]fake google
[BJDCTF 2nd]fake google 进入页面: 试了几下发现输入xxx,一般会按的格式显示, P3's girlfirend is : xxxxx 然后猜测会不会执行代码,发现可以执行 & ...