题目链接

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 405510
 
题意:输入n,m,A,B,C 由ABC和题中提供的函数可以 得到n个数的数组a[n] ,然后输入m个数 表示 数组b[m],现在对于每个b[i]输出a[]数组中的第b[i]+1小的数。题中给出b[]数组的限制bi+bj≤bk is satisfied if bi≠bj, bi<bk and bj<bk;
 
思路:可以发现b[]数组不是很大,对于每个b[i]找a[]数组的第b[i]+1的数时,可以使用nth(a,a+p,a+n) 这个STL函数,进行一次o(n)的排序,使得a[p]之前的数均小于a[p],a[p]之后的数均大于a[p],所以a[p]即为我们要的数。在对每个b[]元素操作时,可以对b[]排序,从大到小进行计算,以为之前排序的右半部分不必再进行排序,这样会减少很多计算量。
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e7+;
unsigned x,y,z, A,B,C;
unsigned a[N];
struct Node
{
int x;
int id;
unsigned y;
}tr[];
bool cmp(const Node s1,const Node s2)
{
return s1.x<s2.x;
}
bool cmp2(const Node s1,const Node s2)
{
return s1.id<s2.id;
} unsigned rng61() {
unsigned t;
x ^= x << ;
x ^= x >> ;
x ^= x << ;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
} int main()
{
///cout << "Hello world!" << endl;
int n,m,Case=1;
while(scanf("%d%d%u%u%u",&n,&m,&A,&B,&C)!=EOF)
{
x = A, y = B, z = C;
for(int i=;i<n;i++) a[i]=rng61();
printf("Case #%d:",Case++);
for(int i=;i<=m;i++) scanf("%d",&tr[i].x),tr[i].id=i;
sort(tr+,tr+m+,cmp); int p=n;
for(int i=m;i>=;i--)
{
int x = tr[i].x;
nth_element(a,a+x,a+p);
p=x;
tr[i].y=a[x];
}
sort(tr+,tr+m+,cmp2);
for(int i=;i<=m;i++) printf(" %u",tr[i].y);
puts("");
}
return ;
}

HDU 6040---Hints of sd0061(STL)的更多相关文章

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

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

  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 —— 2017 Multi-University Training 1

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

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

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

  6. HDU 6040 Hints of sd0061(nth_element)

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

  7. HDU 6040 stl

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

  8. Hints of sd0061(快排思想)

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

  9. HDU - 1022 Train Problem I STL 压栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. Mac OS 的命令行 总结

    du 命令 查看目录下所有文件的大小: du -sh * ls 命令 直接显示当前目录下的所有的非隐藏文件: ls // 怎么在文章中显示不出来?? 显示当前目录下的所有的文件(包括隐藏的): ls ...

  2. 测序分析软件-trimmomatic的记录

    1.下载相关软件,网址:http://www.usadellab.org/cms/index.php?page=trimmomatic,它有源代码和二进制两种文件(建议都下载,然后合并成一个文件,因为 ...

  3. 【转载】SQL Server行转列,列转行

    行转列,列转行是我们在开发过程中经常碰到的问题.行转列一般通过CASE WHEN 语句来实现,也可以通过 SQL SERVER 2005 新增的运算符PIVOT来实现.用传统的方法,比较好理解.层次清 ...

  4. Java中的static、final关键字

    static static 的含义是静态的,是一个静态修饰符,一般来说,被static修饰的有以下几种,类.变量.方法.代码块. static修饰类 Java中普通的类是不允许被声明为静态的,但是有一 ...

  5. Facebook开源Zstandard新型压缩算法代替Zlib 简单使用

    简介 Zstandard(缩写为Zstd)是由Facebook的Yann Collet开发的一个无损数据压缩算法.Zstandard在设计上与DEFLATE(.zip.gzip)算法有着差不多的压缩比 ...

  6. 循环执行sql语句

    DECLARE --声明变量 SQL_ALLTABLES LONG; SQL_INSERT LONG; TYPE THE_CURSOR_TYPE IS REF CURSOR; --定义引用游标的数据类 ...

  7. [0] 错误1“GenerateResource”任务意外失败。....

    解决方案1:关闭VS,删除目录下DEBUG文件夹下所有文件,打开VS重新编译.

  8. oracle备份、还原

    ----第一步:设置空表导出 ----由于Oracle 11G在用EXPORT导出时,空表不能导出.解决方法如下:(11G中有个新特性,当表无数据时,不分配segment,以节省空间) select ...

  9. Java学习笔记--动态代理

    动态代理 1.JDK动态代理 JDK1.3之后,Java提供了动态代理的技术,允许开发者在运行期创建接口的代理实例.JDK的动态代理主要涉及到java.lang.reflect包中的两个类:Proxy ...

  10. 简单轻量级的一套JS 类库(RapidDevelopmentFramework.JS)

    1.最近好久没有更新自己的博客了,一直在考虑自己应该写一些什么.4.2日从苏州回到南京的路上感觉自己的内心些崩溃和失落,我就不多说了? 猛然之间我认为自己需要找一下内心的平衡.决定开发属于自己一套快速 ...