HDU 6040 Hints of sd0061 nth_element函数
Hints of sd0061
There are n noobs in the team, the i-th of which has a rating ai. sd0061 prepares one hint for each contest. The hint for the j-th contest is a number bj, which means that the noob with the (bj+1)-th lowest rating is ordained by sd0061 for the j-th contest.
The coach asks constroy to make a list of contestants. constroy looks into these hints and finds out: bi+bj≤bk is satisfied if bi≠bj, bi<bk and bj<bk.
Now, you are in charge of making the list for constroy.
For each test case:
The first line contains five integers n,m,A,B,C. (1≤n≤107,1≤m≤100)
The second line contains m integers, the i-th of which is the number bi of the i-th hint. (0≤bi<n)
The n noobs' ratings are obtained by calling following function n times, the i-th result of which is ai.
unsigned x = A, y = B, z = C;
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;
}
0 1 2
2 2 2 2 2
1 1
题意:
给你一个长度n的排列,给你生成排列的函数
求m次第k小
题解:
nth_element
表示在数组A的[0,n-1]中找到第k小的并放在第k个位置,并且前k-1个位置均为小于A[k]的数
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 1e7+, M = 1e3+,inf = 2e9; unsigned x,y,z;
unsigned rng61() {
unsigned t;
x ^= x << ;
x ^= x >> ;
x ^= x << ;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
struct ss{
int id,x;
bool operator<(const ss& r) const{
return x < r.x;
}
}b[N];
int n,m;
unsigned ans[N],a[N];
int main() {
int cas = ;
while(scanf("%d%d%u%u%u",&n,&m,&x,&y,&z)!=EOF) {
for(int i = ; i <= m; ++i)
scanf("%d",&b[i].x),b[i].id = i;
for(int i = ; i < n; ++i) a[i] = rng61();
sort(b+,b+m+);
b[m+].x = n;
for(int i = m; i >= ; --i) {
nth_element(a,a+b[i].x,a+b[i+].x);
ans[b[i].id] = a[b[i].x];
}
printf("Case #%d: ",cas++);
for(int i = ; i < m; ++i) printf("%u ",ans[i]);
printf("%u\n",ans[m]);
}
}
HDU 6040 Hints of sd0061 nth_element函数的更多相关文章
- 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) ,对于每个询 ...
- 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 —— 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(nth_element)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...
- HDU 6040 Hints of sd0061(划分高低位查找)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...
- Hints of sd0061(快排思想)
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- 【快速选择算法与nth_element函数】【续UVA11300 】
在白书中提到了一种O(n)级别的寻找中位数算法 就是我们今天要介绍的主角 快速选择算法 类似快排 选择一个比较元素 进行递归处理寻找第k大元素 假设最后比较元素到了i 以下描述是我写快排的常用字符 所 ...
- HDU 6040 stl
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- nth_element函数
使用方法:nth_element(start, start+n, end) 使第n大元素处于第n位置(从0开始,其位置是下标为n的元素),并且比这个元素小的元素都排在这个元素之前,比这个元素大的元素都 ...
随机推荐
- Codeforces Round #401 (Div. 2) 离翻身就差2分钟
Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...
- MySQL5.7 服务 crash 后无法启动
事发背景 测试环境更换数据盘,直接采取在线将数据目录暴力拷贝到新盘,然后将原服务关闭,启用新盘. 服务是可以正常启动的,但是没多会开发就反应服务down了,错误日志输出 -- :: InnoDB: F ...
- 洛谷3830 [SHOI2012]随机树 【概率dp】
题目 输入格式 输入仅有一行,包含两个正整数 q, n,分别表示问题编号以及叶结点的个数. 输出格式 输出仅有一行,包含一个实数 d,四舍五入精确到小数点后 6 位.如果 q = 1,则 d 表示叶结 ...
- VBA Split()函数
Split()函数返回一个数组,其中包含基于分隔符分割的特定数量的值. 语法 Split(expression[,delimiter[,count[,compare]]]) 参数说明 Expressi ...
- Snoop resynchronization mechanism to preserve read ordering
A processor employing a post-cache (LS2) buffer. Loads are stored into the LS2buffer after probing t ...
- PatentTips - Optimizing Write Combining Performance
BACKGROUND OF THE INVENTION The use of a cache memory with a processor facilitates the reduction of ...
- Python爬虫--beautifulsoup 4 用法
Beautiful Soup将复杂HTML文档转换成一个复杂的树形结构, 每个节点都是Python对象,所有对象可以归纳为4种: Tag , NavigableString , BeautifulSo ...
- iOS7坐标上移44pt的解决
在iOS7中,引入一个新的属性,叫[UIViewController setEdgesForExtendedLayout:],它的默认值是UIRectEdgeAll.当容器为UINavigationC ...
- git status检测不到文件变化
SourceTree(Git)无法检测新增文件的解决方法 有时候使用git管理软件SourceTree会遇到往项目里新增了文件,软件却没有任何反应的问题,这多发生在git合并出错而只能重新git的情况 ...
- c++中c_str()函数
https://zhidao.baidu.com/question/104592558.html