HDU 6040 - Hints of sd0061 | 2017 Multi-University Training Contest 1
/*
HDU 6040 - Hints of sd0061 [ 第k小数查询,剪枝 ]
题意:
给出随机数列 a[N] (N < 1e7)
询问 b[M] (M < 100) ,对于每个询问输出第 b[i]+1小的数字
满足对任意 i,j,k,若b[i] <= b[k] && b[j] <= b[k] 则一定有 b[i]+b[j] <= b[k]
分析:
用 nth_element() 解决第k小数问题
先将询问排序,可以从小到大或从大到小解决,就能每次不断缩小枚举区间
根据询问的限制条件,选择从大到小解决,这样每次剪去的区间至少是一半
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
unsigned x, y, z;
unsigned rng61() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
const int N = 1e7+5;
unsigned a[N];
unsigned A, B, C, n, m;
void init()
{
x = A, y = B, z = C;
for (int i = 0; i < n; i++) a[i] = rng61();
}
struct Q{
int id, x;
}q[105];
bool cmp(Q a, Q b) {
return a.x < b.x;
}
unsigned ans[105];
int main()
{
int tt = 0;
while (~scanf("%u%u%u%u%u", &n, &m, &A, &B, &C))
{
for (int i = 0; i < m; i++)
{
scanf("%d", &q[i].x);
q[i].id = i;
}
init();
sort(q, q+m, cmp);
q[m].x = n;
for (int i = m-1; i >= 0; i--)
{
if (q[i].x == q[i+1].x) {
ans[q[i].id] = ans[q[i+1].id]; continue;
}
nth_element(a, a+q[i].x, a+q[i+1].x);
ans[q[i].id] = a[q[i].x];
}
printf("Case #%d:", ++tt);
for (int i = 0; i < m; i++) printf(" %u", ans[i]);
puts("");
}
}
HDU 6040 - Hints of sd0061 | 2017 Multi-University Training Contest 1的更多相关文章
- HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- hdu 6040 Hints of sd0061(stl: nth_element(arr,arr+k,arr+n))
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- HDU 6040 Hints of sd0061 nth_element函数
Hints of sd0061 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired ...
- HDU 6040 Hints of sd0061(划分高低位查找)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...
- HDU 6040 Hints of sd0061(nth_element)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...
- HDU 6162 - Ch’s gift | 2017 ZJUT Multi-University Training 9
/* HDU 6162 - Ch’s gift [ LCA,线段树 ] | 2017 ZJUT Multi-University Training 9 题意: N节点的树,Q组询问 每次询问s,t两节 ...
- 2017 Wuhan University Programming Contest (Online Round) Lost in WHU 矩阵快速幂 一个无向图,求从1出发到达n最多经过T条边的方法数,边可以重复经过,到达n之后不可以再离开。
/** 题目:Lost in WHU 链接:https://oj.ejq.me/problem/26 题意:一个无向图,求从1出发到达n最多经过T条边的方法数,边可以重复经过,到达n之后不可以再离开. ...
- 2017 Wuhan University Programming Contest (Online Round) C. Divide by Six 分析+模拟
/** 题目:C. Divide by Six 链接:https://oj.ejq.me/problem/24 题意:给定一个数,这个数位数达到1e5,可能存在前导0.问为了使这个数是6的倍数,且没有 ...
- 2017 Wuhan University Programming Contest (Online Round) B Color 树形dp求染色方法数
/** 题目:Color 链接:https://oj.ejq.me/problem/23 题意:给定一颗树,将树上的点最多染成m种颜色,有些节点不可以染成某些颜色.相邻节点颜色不同.求染色方法数. 思 ...
随机推荐
- sqlserver中分页的方式
1.使用top进行: 1.select top 页大小 * from 表名where id not in(select top 页大小*(查询第几页-1) id from 表名 order by id ...
- 基于Docker 搭建 Jenkins
⒈下载镜像 要使用最新的LTS: docker pull jenkins/jenkins:lts 要使用最新的每周 docker pull jenkins/jenkins ⒉运行 docker run ...
- es reindex
# 添加mapping: url -X POST 'http://127.0.0.1:9200/indexName/typeName/_mapping?pretty' -d '{ "type ...
- Fabric的简介
1,初识fabric 1,什么是fabric fabric是一个Python的库和命令行工具,用来提高基于SSH的应用部署和系统管理的效率. 简单来说: (1)一个让你通过命令行执行无参数python ...
- Python 风格指南
https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/contents/ 目前个人遵循的基本规范 ...
- 服务端相关知识学习(二)之Zookeeper可以干什么
Zookeeper主要可以干哪些事情 配置管理,名字服务,提供分布式同步以及集群管理.那这些服务又到底是什么呢?我们为什么需要这样的服务?我们又为什么要使用Zookeeper来实现呢,使用Zookee ...
- day06 Python class基础篇
一.目录 1.类与对象的概述 2.封装 3.继承 4.多态 5.类的成员 6.类与类之间的关系 7.私有 二. 内容讲解 一.类与对象的概述 类是对一系列具有相同属性的事物的抽象,相同于设计图纸,而对 ...
- jQuery EasyUI中DataGird动态生成列的方法
EasyUI中使用DataGird显示数据列表中,有时需要根据需要显示不同的列,例如,在权限管理中,不同的用户登录后只能查看自己权限范围内的列表字段,这就需要DataGird动态组合列,下面介绍Eas ...
- docker 安装php
nginx :docker pull nginx docker run -p 80:80 --name nginx -v /usr/local/nginx/www:/www -v /usr/local ...
- MongoDB 各个位版本下载地址
官网首页下载需要填写资料 windows版本 Linux版本