题目链接

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.

  1. 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[]排序,从大到小进行计算,以为之前排序的右半部分不必再进行排序,这样会减少很多计算量。
 
代码如下:
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstring>
  5. using namespace std;
  6. const int N=1e7+;
  7. unsigned x,y,z, A,B,C;
  8. unsigned a[N];
  9. struct Node
  10. {
  11. int x;
  12. int id;
  13. unsigned y;
  14. }tr[];
  15. bool cmp(const Node s1,const Node s2)
  16. {
  17. return s1.x<s2.x;
  18. }
  19. bool cmp2(const Node s1,const Node s2)
  20. {
  21. return s1.id<s2.id;
  22. }
  23.  
  24. unsigned rng61() {
  25. unsigned t;
  26. x ^= x << ;
  27. x ^= x >> ;
  28. x ^= x << ;
  29. t = x;
  30. x = y;
  31. y = z;
  32. z = t ^ x ^ y;
  33. return z;
  34. }
  35.  
  36. int main()
  37. {
  38. ///cout << "Hello world!" << endl;
  39. int n,m,Case=1;
  40. while(scanf("%d%d%u%u%u",&n,&m,&A,&B,&C)!=EOF)
  41. {
  42. x = A, y = B, z = C;
  43. for(int i=;i<n;i++) a[i]=rng61();
  44. printf("Case #%d:",Case++);
  45. for(int i=;i<=m;i++) scanf("%d",&tr[i].x),tr[i].id=i;
  46. sort(tr+,tr+m+,cmp);
  47.  
  48. int p=n;
  49. for(int i=m;i>=;i--)
  50. {
  51. int x = tr[i].x;
  52. nth_element(a,a+x,a+p);
  53. p=x;
  54. tr[i].y=a[x];
  55. }
  56. sort(tr+,tr+m+,cmp2);
  57. for(int i=;i<=m;i++) printf(" %u",tr[i].y);
  58. puts("");
  59. }
  60. return ;
  61. }

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. git 知识点汇总

    git commit git commit 命令执行后, git 主要执行了三个操作: 为每一个文件生成一个快照 每一个文件其实是真的数据, 所以 git 会把整个文件内容转成二进制, 然后经过压缩直 ...

  2. PHP中单引号和双引号的区别

    双引号里面的字段会经过编译器解释,然后再当作HTML代码输出:单引号里面的不进行解释,直接输出: PHP引号使用原则 1.字符串的值用单引号 2.PHP中尽量用单引号,HTML代码全部用双引号 3.在 ...

  3. 转化来的图标用法symbol引用‘font-class引用及Unicode引用

  4. Silverlight将Excel导入到SQLserver数据库

    最近纠结于读取Excel模板数据,将数据导入SQLServer的Silverlight实现,本文将实现代码贴出,作为一个简单的例子,方便各位: 1.先设计前台界面新建Silverlight5.0应用程 ...

  5. 关于MATLAB处理大数据坐标文件2017527

    第一次提交数据: 今天用了8个特征,加上的这一个特征是 从3000条测试数据中测试失败的数据总结出来的树的数目为50再次使用3000条测试数据测试结果-- 结果不错: 99%但是运行官网数据结果分数- ...

  6. ubuntu 16.04.2 源码安装gitlab并且利用runner持续集成

    参考原档:https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https 本章只 ...

  7. Java软件系统功能设计实战训练视频教程

    Java软件系统功能设计实战训练视频教程 第01节课:整体课程介绍和杂项介绍第02节课:软件功能设计常见理念和方法第03节课:关于软件设计的一些思考第04节课:第一周作业的业务和相应模式:综合应用简单 ...

  8. 怎么样刷新frameset的整个页面

    <a href="main.html?a=2" target="_parent">?  设置a链接的target属性值为_parent即可

  9. Vue.js 基础指令实例讲解(各种数据绑定、表单渲染大总结)——新手入门、高手进阶

    Vue.js 是一套构建用户界面的渐进式框架.他自身不是一个全能框架--只聚焦于视图层.因此它非常容易学习,非常容易与其它库或已有项目整合.在与相关工具和支持库一起使用时,Vue.js 也能完美地驱动 ...

  10. RunTime 运行时

    简单介绍RunTime 运行时的用法 以下操作都需要导入头文件 #import <objc/message.h> #pragma mark -- 发消息 //OC方法调用的本质就是让对象发 ...