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

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
 
Source
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6055 6054 6053 6052 6051 
 
 

题意:给你一个长度为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))的更多相关文章

  1. HDU 6040 Hints of sd0061(nth_element)

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

  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(划分高低位查找)

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

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

  6. HDU 6040 stl

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

  7. Hints of sd0061(快排思想)

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

  8. C/C++ char* arr与char arr[]的区别(反汇编解析)

    写作日期:2016.08.31 修改日期:2016.09.01 .2016.09.02. 交流qq:992591601 用了几天时间复习了下C语言.对于C语言的字符串操作有些不习惯,于是作为练习,写下 ...

  9. Java: arr==null vs arr.length==0

    当 arr 是一个array时,写Java开始的corner case常常会写类似下面的语句: if(arr == null || arr.length == 0){ return 0; } 其实这是 ...

随机推荐

  1. cocosBuider 控件命名的坑

    这几天遇到了各种坑.... 各种控件名字问题.... bool CLevelLayer::onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, ...

  2. 无密码ssh操作步骤备忘

    需求:A机器无密码登陆到B机器 1.A机器执行   ssh-keygen -t rsa  ,在~/.ssh/下生成id_rsa 和  id_rsa.pub两个文件,其中id_rsa.pub是公匙 2. ...

  3. 十八般武艺之 Runloop

    嗯,runloop ,看过,用过.但是有时候突然被问到,总是不能很好的描述给他人,也许是程序员本来口拙的缘故吧.另外,也是对runloop还是理解的不够透彻. 于是乎,决定重新整理一下,加深一下印象. ...

  4. JS动态事件绑定问题

    今天搞一个连环套的动态选项展示,需要给下拉框动态绑定事件,谁知绑定中出现问题,总是执行第一次绑定的时间而后续绑定的事件没有被触发. //重写增加行方法 function initMainItem(gr ...

  5. ::before ::after CSS3中的伪类和伪元素

    ::before和::after伪元素的用法 一.介绍 css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:link,:active,:target,:not(),:fo ...

  6. 20145335郝昊《java程序设计》第4周学习总结

    20145335郝昊 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 何谓继承: 概念: 面向对象中,为避免多个类间重复定义共同行为.(简单说就是将相同的程序代码提升为父类. ...

  7. C++ 单词接龙

    问题描述: 拉姆刚刚开始学习英文字母,对单词排序很感兴趣,他能够迅速确定是否可以将这些单词排列在一个列表中,使得该列表中任何单词的首字母与前一个单词的尾字母相同,力能编写一个计算机程序帮助拉姆进行判断 ...

  8. 异步:asyncio和aiohttp的一些应用(2)

    转自:原文链接:http://www.cnblogs.com/ssyfj/p/9222342.html 1.aiohttp的简单使用(配合asyncio模块) import asyncio,aioht ...

  9. 爬虫框架Scrapy之Downloader Middlewares

    反反爬虫相关机制 Some websites implement certain measures to prevent bots from crawling them, with varying d ...

  10. git branch 新建,推送与删除

    在开发的许多时候我们都需要使用git提供的分支管理功能. 1.新建本地分支:git checkout -b test  新建一个名为:test 的本地分支. 2.提交本地分支:git push ori ...