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)
Total Submission(s): 2262 Accepted Submission(s): 673
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;
}
题意:给你一个长度为n的序列,序列由题面给的函数生成。然后m次询问,询问这个序列上第bi小的数。
解题思路:新学习了一个STL,C++中的nth_element(arr,arr+k,arr+n),将长度为n的数组arr进行划分,第k-1位置上就是第k大的数(下标从0开始算),这个函数近似线性,在找到第k大的时候,前k-1个数均是小于arr[k]的,因为输入保证任意两个小的之和小于第三个,所以查询数列的间隔一定大于等于斐波那契,所以从大到小查询的话,每次至少能去掉一半的区间,根据这个可以减少搜索量
hdu上要用G++交,C++超时
#include <iostream>
#include<cstdio>
#include<functional>
#include<cstring>
#include<algorithm>
using namespace std; unsigned a[];
struct node
{
int k,id;
}b[];
int n,m;
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;
}
bool cmp(node a,node b)
{
return a.k>b.k;
}
bool cmp2(node a,node b)
{
return a.id<b.id;
}
int main()
{
int cas=;
while(~scanf("%d%d%u%u%u",&n,&m,&x,&y,&z))
{
for(int i=;i<=m;i++)
{
scanf("%d",&b[i].k);
b[i].id=i;
}
for(int i=;i<n;i++) a[i]=rng61(); sort(b+,b++m,cmp);
b[].k=n;
for(int i=;i<=m;i++)
nth_element(a,a+b[i].k,a+b[i-].k);
sort(b+,b++m,cmp2); printf("Case #%d:",++cas);
for(int i=;i<=m;i++)
printf(" %u",a[b[i].k]);
printf("\n");
}
return ;
}
hdu 6040 Hints of sd0061(stl: nth_element(arr,arr+k,arr+n))的更多相关文章
- HDU 6040 Hints of sd0061(nth_element)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...
- 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 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 —— 2017 Multi-University Training 1
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- HDU 6040 stl
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- Hints of sd0061(快排思想)
Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- C/C++ char* arr与char arr[]的区别(反汇编解析)
写作日期:2016.08.31 修改日期:2016.09.01 .2016.09.02. 交流qq:992591601 用了几天时间复习了下C语言.对于C语言的字符串操作有些不习惯,于是作为练习,写下 ...
- Java: arr==null vs arr.length==0
当 arr 是一个array时,写Java开始的corner case常常会写类似下面的语句: if(arr == null || arr.length == 0){ return 0; } 其实这是 ...
随机推荐
- Winter-1-B Sum 解题报告及测试数据
Time Limit:500MS Memory Limit:32768KB Description Hey, welcome to HDOJ(Hangzhou Dianzi University O ...
- spray-json
spray-json是一个轻量级的,简介的和高效的使用Scala实现的json 它拥有以下特征: 一个简单不可变的模型的json语言元素 一个高效的json解析器 可选择既紧凑又漂亮的json到str ...
- Python面试题之Python反射机制
0x00 前言 def f1(): print('f1') def f2(): print('f2') def f3(): print('f3') def f4(): print('f4') a = ...
- CSS 图像拼合技术
CSS 图像拼合技术 一.图像拼合 图像拼合就是单个图像的集合. 有许多图像的网页可能需要很长的时间来加载和生成多个服务器的请求. 使用图像拼合会降低服务器的请求数量,并节省带宽. 二.图像拼合 - ...
- php下获取http状态的实现代码
在项目开发中,有时我们需要知道远程的URL地址是否能访问正常,判断其正常与否后进行下一步的操作,那么在PHP中如何获取远程HTTP的状态呢? 文件preg.php header("HTTP/ ...
- 20145231熊梓宏 《网络对抗》 实验5 MSF基础应用
20145231熊梓宏 <网络对抗> 实验5 MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit就相当于是就是渗透攻击,其 ...
- git将本地已经存在的分支和一个指定的远端分支建立映射关系
Make an existing Git branch track a remote branch? Given a branch foo and a remote upstream: As of G ...
- 【Network architecture】Rethinking the Inception Architecture for Computer Vision(inception-v3)论文解析
目录 0. paper link 1. Overview 2. Four General Design Principles 3. Factorizing Convolutions with Larg ...
- HDU 3594 Cactus(仙人掌问题)
http://acm.hdu.edu.cn/showproblem.php?pid=3594 题意: 一个有向图,判断是否强连通和每条边只在一个环中. 思路: 仙人掌问题. 用Tarjan算法判断强连 ...
- mac terminal update management pack
npm -g outdated npm -g install npm@6.4.1