题目链接: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<桶 水题>的更多相关文章

  1. kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)

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

  2. HDU1029 - Ignatius and the Princess IV【水题】

    给你n个数字,请你找出出现至少(n+1)/2次的数字. 输入 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行 ...

  3. 【HDU - 1029】Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV  先搬中文 Descriptions:   给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...

  4. Ignatius and the Princess IV (水题)

    "OK, you are not too bad, em... But you can never pass the next test." feng5166 says.  &qu ...

  5. HDU1029 Ignatius and the Princess IV (水题)

    <题目链接> 题目大意:给你一段序列,问你在这个序列中出现次数至少为 (n+1)/2 的数是哪个. 解题分析: 本题是一道水题,如果用map来做的话,就非常简单,但是另一个做法还比较巧妙. ...

  6. 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 ...

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

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

  8. (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 ...

  9. hdu 1029 Ignatius ans the Princess IV

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

随机推荐

  1. py基础之模块与包

    '''模块:当代码越来越多时,将所有代码放入一个文件中便会无法维护,所以放到多个文件中去,这样每一个py文件就是一个模块 包:模块越来越多时容易重名,便将模块放入不同的包中,每个包中必须有一个__in ...

  2. 关于地址栏url的一些小结

    1.获取整个地址栏地址 //获取整个地址栏地址 var href = window.location.href; console.log(href); 以上代码就是获取整个url地址 2.获取url协 ...

  3. js轮询及踩过的坑

    背景 下午四点,天气晴朗,阳光明媚,等着下班产品:我希望页面上的这个数据实时变化开发:···,可以,用那个叫着WebSocket的东西,再找一个封装好框架,如:mqtt(感觉自己好机智)产品:要开发好 ...

  4. 第二章、 Vue 起步

    2-2.编写hello world 首先创建vue实例,然后实例接收一些配置项,el表示实例负责管理的区域,data表示区域内的数据 两秒后内容变为bye world 其中app表示实例对象,$dat ...

  5. flask 对于用户登录保持状态 flask_login

    先加载flask_login ext.py  在app下的__init__.py 进行引用把,我就不写了 login_manager = LoginManager() # 如果没有登录则重定向到该蓝图 ...

  6. flask 部署外部访问

    在 app.run(host='0.0.0.0',port=5000) 可以让外部客户端进行访问,访问地址是flask服务器的ip地址和你设置的端口(端口注意不要占用其他端口,如果是阿里云有可能要设置 ...

  7. go学习第四天、条件和循环

    循环 Go语言仅支持循环关键字 for for i := 0; i<5; i++ 示例 while 条件循环 while(n<5) n := 0 for n < 5 { n++ fm ...

  8. C# Socket编程实现简单的局域网聊天器

    目录 前言 编码 服务端监听接口 客户端连接接口 文字发送接口 文件发送接口 信息接收接口(文字与文件) 使用 注意事项 源码 前言 最近在学习C# Socket相关的知识,学习之余,动手做了一个简单 ...

  9. js 数组 方法

    instanceof 检测一个对象是否是数组;(用来对付复杂数据类型;)// 简单数据类型 typeof ;A instanceof B // A是不是B造出来的;例: var arr = [1,2, ...

  10. Anaconda3环境下安装OpenCV(cv2)

    Anaconda3环境下安装OpenCV(cv2) 主要步骤 1 首先查看自己的Anaconda安装的python版本 2 下载相应的OpenCv.whl文件 3 使用cmd安装.whl文件 查看自己 ...