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的元素),并且比这个元素小的元素都排在这个元素之前,比这个元素大的元素都 ...
随机推荐
- TOJ 4804: 树网的核
这个是NOIP的提高组的题 4804: 树网的核 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Sub ...
- 九度oj 题目1254:N皇后问题
题目描述: N皇后问题,即在N*N的方格棋盘内放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在同一斜线上.因为皇后可以直走,横走和斜走如下图). 你的任务是,对 ...
- 【Luogu】P1896互不侵犯King(状压DP)
题目链接 真是可恶,被数据范围坑了一把.想要一遍AC的希望破灭了…… 以后大家在做状压DP的时候一定要开long long…… 设f[i][j][k]表示考虑前i行,总共放了j个King,第i行状态为 ...
- 通过new ClasspathApplicationContext("applicationContext.xml")找不到文件时
可以把applicationContext.xml放到/WEB-INF/classes目录下使用先说:ClassPathXmlApplicationContext 这个类,默认获取的是WEB-INF/ ...
- 虚拟机vmnet0、vmnet1和vmnet8的区别 虚拟网卡概述
vmnet0,实际上就是一个虚拟的网桥 vmnet0,实际上就是一个虚拟的网桥,这个网桥有很若干个端口,一个端口用于连接你的Host,一个端口用于连接你的虚拟机,他们的位置是对等的,谁也不是谁的网关. ...
- 51nod1053 最大M子段和 V2
$n \leq 50000$的序列,问选不超过$m \leq 50000$个区间使得和最大. 如果正数区间总数比$m$小那肯定全选.否则有两种方式减少区间数量:丢掉一个正区间:补一个负区间连接两个正区 ...
- dedecms--需要注意的细节
在系统的系统配置参数里面修改一些参数 1:站点设置: (1):站点根网址:本地测试的话:就是你设置的虚拟主机:http://www.abc.cc (2):网页主页链接:为空 2:核心设置: DedeC ...
- MyBatis的参数,不能传入null
今天在调试的过程中发现一个bug,把传入的参数写到查询分析器中执行没有问题,但是在程序中执行就报错:org.springframework.jdbc.UncategorizedSQLException ...
- Codeforces 837D Round Subset(背包)
题目链接 Round Subset 题意 在n个数中选择k个数,求这k个数乘积末尾0个数的最大值. 首先我们预处理出每个数5的因子个数c[i]和2的因子个数d[i] 然后就可以背包了. 设f[i] ...
- Rmq Problem
大视野——3339: Rmq Problem Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1192 Solved: 620[Submit][Sta ...