Hints of sd0061

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2297    Accepted Submission(s): 687

Problem Description
sd0061, the legend of Beihang University ACM-ICPC Team, retired last year leaving a group of noobs. Noobs have no idea how to deal with m coming contests. sd0061 has left a set of hints for them.

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.

 
Input
There are multiple test cases (about 10).

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;
}
Output
For each test case, output "Case #x: y1 y2 ⋯ ym" in one line (without quotes), where x indicates the case number starting from 1 and yi (1≤i≤m) denotes the rating of noob for the i-th contest of corresponding case.
 
Sample Input
3 3 1 1 1
0 1 2
2 2 2 2 2
1 1
 
Sample Output
Case #1: 1 1 202755 Case #2: 405510 40551
 
 
题目大意:用题目所给的程序生成a数组,m个询问,每个询问输出a从小至大排序后第bi个数。
思路:按照题意进行排序,不过输出ai前用sort会超时,用nth_element()可以避免TLE。
 
AC代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e7+;
unsigned n, m;
unsigned rat[MAXN], b[MAXN],p[MAXN], a[MAXN];
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(int s, int t)
{
return b[s]<b[t];
}
int main()
{
int k=;
while(~scanf("%d %d %u %u %u", &n, &m, &x, &y, &z))
{
for(int i=;i<m;i++){
p[i]=i;
scanf("%d", b+i);
} for(int i=;i<n;i++)
rat[i]=rng61();
sort(p, p+m,cmp);
b[p[m]=m]=n;
for(int i=m-;i>=;i--){
if(b[p[i]]==b[p[i+]]){
a[p[i]]=a[p[i+]];
//continue;
}
nth_element(rat, rat+b[p[i]], rat+b[p[i+]]);
a[p[i]]=rat[b[p[i]]];
}
printf("Case #%d:", ++k);
for(int i=;i<m;i++)
printf(" %u", a[i]);
printf("\n");
}
}

HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1的更多相关文章

  1. 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) ,对于每个询 ...

  2. 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 ...

  3. HDU 6040 Hints of sd0061 nth_element函数

    Hints of sd0061 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired ...

  4. HDU 6040 Hints of sd0061(划分高低位查找)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...

  5. HDU 6040 Hints of sd0061(nth_element)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...

  6. 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两节 ...

  7. HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9

    /* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问 ...

  8. HDU 6040 stl

    Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  9. Hints of sd0061(快排思想)

    Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

随机推荐

  1. Entity Framework Code First数据库连接 转载 https://www.cnblogs.com/libingql/p/3351275.html

    Entity Framework Code First数据库连接   1. 安装Entity Framework 使用NuGet安装Entity Framework程序包:工具->库程序包管理器 ...

  2. ETCD 简介及基本用法

    ETCD 项目地址 ETCD 官方文档 1. 简介 ETCD 是一个高可用的分布式键值数据库,可用于服务发现.ETCD 采用 raft 一致性算法,基于 Go 语言实现. 特点 简单:安装配置使用简单 ...

  3. WEB服务端安全---文件上传漏洞

    1.简述 文件上传漏洞是指用户上传了一个可执行的脚本文件,并通过此脚本文件获得了执行服务端命令的能力.这种攻击方式是最直接和有效的,而且互联网中我们经常会用到文件上传功能,它本身是没有问题的,正常的业 ...

  4. upc组队赛17 Stone Game【极小值】

    Stone Game 题目链接 题目描述 Alice and Bob are always playing game! The game today is about taking out stone ...

  5. C++学习笔记(一)--基础

    1.遵循标准C++,主函数类型为int,成功返回值为0,异常返回默认为-1. 2.使用系统函数库,必须加上 using namespace std,因为C++的标准库函数是在命名空间std中: 3.输 ...

  6. 全栈开发系列学习2——django项目搭建

    项目代码:http://yunpan.cn/cHajgT4HvgHqx (提取码:8350) 配置项目: 1. 首先确保你的机器安装了python和pip,这两种安装比较简单,这里就不说了. 2. 在 ...

  7. git 报错

    -bash: git: command not found export PATH=$PATH:/usr/local/git/bin 使用git clone出现 fatal: unable to ac ...

  8. Zabbix学习笔记(yum源安装)

    Zabbix学习笔记(yum源安装) 链接:https://pan.baidu.com/s/19RXhumkB-ulpI4BGOa5b_A 提取码:115h 复制这段内容后打开百度网盘手机App,操作 ...

  9. [HNOI2015]亚瑟王(概率dp)

    题面太长了就不复制了,传送门 一道做了还是很懵逼的题目,感觉以后碰到类似的还是不会,果然HNOI题目很皮. 题解传送 补充一下吧.//感觉他的博客已经写得很好了......Orz 需要的可以两边一起看 ...

  10. Ubuntu 服务器Webmin错误的解决

    一:This web server is running in SSL mode. Try the URL https://***********:10000/ instead. 解决方案: 1.ss ...