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种颜色,有些节点不可以染成某些颜色.相邻节点颜色不同.求染色方法数. 思 ...
随机推荐
- 【Python】【demo实验9】【练习实例】【三数排序】
原题: 输入三个整数x,y,z,请把这三个数由小到大输出. 我的解法: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- # 输入三 ...
- DOM、BOM
DOM DOM 是 W3C(万维网联盟)的标准. DOM 定义了访问 HTML 和 XML 文档的标准: “W3C 文档对象模型 (DOM) 是中立于平台和语言的接口,它允许程序和脚本动态地访问和更新 ...
- Tomcat: has been normalized to [null] which is not valid
环境 tomcat 8.5 原因 在使用相对路径加载配置文件时,如果相对路径超出了 tomcat 容器的根目录,那么 tomcat 会提示 xxx has been normalized to [nu ...
- T100错误信息提示方式
例如: IF g_browser_cnt = THEN INITIALIZE g_errparam TO NULL LET g_errparam.extend = "" LET g ...
- 北电之死:谁谋杀了华为的对手?——银湖资本(Silver Lake)董事总经理爱德华·詹德出任CEO,既不了解华为,也不重视中国,直截了当地否决了收购华为
作者:戴老板:微信公众号:饭统戴老板(ID: worldofboss) 2003年5月,北京SARS疫情紧张,摩托罗拉集团总裁迈克·扎菲罗夫斯基(Mike Zafirovski)却准备不走寻常路,决定 ...
- Hinton等人新研究:如何更好地测量神经网络表示相似性
Hinton等人新研究:如何更好地测量神经网络表示相似性 2019年05月22日 08:39:15 喜欢打酱油的老鸟 阅读数 177更多 分类专栏: 人工智能 https://www.toutia ...
- 【原创】大叔问题定位分享(33)oozie提交任务报错ArithmeticException: / by zero
oozie提交workflow后执行task报错: 2019-07-04 17:19:00,559 ERROR [RMCommunicator Allocator] org.apache.hadoop ...
- vue+ element table如何给指定的单元格添加点击事件?
今天使用vue,以及element-ui这个框架时,发现业务需要在表格里加一个连接跳转,当时立刻打开element的官网,进行查看http://element-cn.eleme.io/#/zh-CN/ ...
- uni app以及小程序 --环境搭建以及编辑器
https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html 根据以上网页下载自己电脑相应的版本的微信开发者工具(目录 ...
- 阿里云环境中配置tomcat7可能出现的问题及解决方法
前提是安装好了tomcat,但是输入ip+端口无法访问,那么情况有一下几种 (1)可能防火墙没有关闭 systemctl stop firewalld.service #停止firewall syst ...