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种颜色,有些节点不可以染成某些颜色.相邻节点颜色不同.求染色方法数. 思 ...
随机推荐
- Netty对常用编解码的支持
参考文献:极客时间傅健老师的<Netty源码剖析与实战>Talk is cheap.show me the code! Netty对编解码的支持 打开Netty的源码,它对很多的编码器都提 ...
- typora数学符号大全
- VerilogHDL学习
No.1 Verilog HDL程序结构 Verilog 描述硬件的基本设计单元是模块 module 复杂的电子电路构建主要是通过模块之间的相互连接调用来实现的,在Verilog中将模块包含在关键字 ...
- Cow and Snacks(吃点心--图论转换) Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1209/problem/D 有n个点心,有k个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...
- php 中文unicode 互转
/** * $str 原始中文字符串 * $encoding 原始字符串的编码,默认GBK * $prefix 编码后的前缀,默认"&#" * $postfix 编码后的后 ...
- 2 - sat 模板(自用)
2-sat一个变量两种状态符合条件的状态建边找强连通,两两成立1 - n 为第一状态(n + 1) - (n + n) 为第二状态 例题模板 链接一 POJ 3207 Ikki's Story IV ...
- Good Triple CodeForces - 1169D (等差子序列)
大意: 给定01字符串, 求有多少个区间$[l,r]$, 使得存在正整数$x,k$满足$1\le x,k\le n,l\le x<x+2k\le r,s_x=s_{x+k}=s_{x+2k}$. ...
- 交替方向乘子法(ADMM)的原理和流程的白话总结
交替方向乘子法(ADMM)的原理和流程的白话总结 2018年08月27日 14:26:42 qauchangqingwei 阅读数 19925更多 分类专栏: 图像处理 作者:大大大的v链接:ht ...
- HashSet——add remove contains方法底层代码分析(hashCode equals 方法的重写)
引言:我们都知道HashSet这个类有add remove contains方法,但是我们要深刻理解到底是怎么判断它是否重复加入了,什么时候才移除,什么时候才算是包括????????? add ...
- django 上传路径至vue处理组件加载
1,在主目录(项目目录)下新建中间件middleware.py文件 写入 from django.utils.deprecation import MiddlewareMixin from djang ...