[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 ( ...
随机推荐
- vue中的自定义分页插件组件
介绍一下,已经有很多的vue分页的组件了,大家都是大同小易,那么我就结合自身的使用,写出了一片文章 首先在新建一个分页模块 在模块中引入相应的代码,(内有详细的注释) template中 <di ...
- VueX状态管理器 的应用
VueX状态管理器 cnpm i vuex axios -S 1 创建Vuex 仓库 import Vue from 'vue' import Vuex from 'vuex' vue.use(Vue ...
- python之路-基本数据类型之list列表
1.概述 列表是python的基本数据类型之一,是一个可变的数据类型,用[]方括号表示,每一项元素使用逗号隔开,可以装大量的数据 #先来看看list列表的源码写了什么,方法:按ctrl+鼠标左键点li ...
- javaee作业
一.单选题(共5题,50.0分) 1 在SqlSession对象的openSession()方法中,不能作为参数executorType的可选值 的是( ). A. ExecutorTyp ...
- [头脑风暴] 解读Docker Bridge网络模型
背景 这几天在研究Kubernetes, 遇到一个有意思的nodejs镜像:luksa/kubia # 不带端口映射启动容器docker run -it -d luksa/kubia# 连接到默认的B ...
- spring boot 学习笔记(一)
学习链接:http://www.cnblogs.com/ityouknow/category/914493.html 定义 spring boot 是由pivotal 团队提供的权限框架,设计目的是用 ...
- vscode 新建 springboot java项目
vscode 新建 springboot java项目 1. 安装javaJDK 软件下载 下载地址: https://www.oracle.com/technetwork/java/javase/d ...
- 动态高度计算 height window.addEventListener('resize', () => {
created() { window.addEventListener('resize', () => { }) },
- mysql数据库设计文档-导出字段设计
navicat 是我一直在使用的一个数据库操作工具,非常方便快捷.如果没有可用navicat可以留言邮箱我直接发您. 今天来介绍一下使用navicat导出数据库字段设计.废话不多说,先看导出效果. 查 ...
- 解决2020-3-27 github无法访问
早上的github无法访问了 查找资料后,发现可以修改 hosts 文件 右键 属性 将只读去掉 进行修改 其中的ip去如下地址拿 试一下,大功告成