题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6040

题意:不知道北航的同学为何解释题意之前都要想一段故事,导致刚开始题意不是很懂,题意就是给你n,m,A,B,C三个点,可以用以下这段代码生成n个随机数,赋值num[N],然后给你m个数,作为m次询问赋值给q[N]。然后问你第i次询问对于区间(0,n)这个区间中第q[i]+1小的数。

unsigned x = A, y = B, z = C;
unsigned rng61() {
unsigned t;
x ^= x << ;
x ^= x >> ;
x ^= x << ;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}

思路:好吧……我是看了别人的代码,学习了这个线性求k大的姿势,就是用了一个STL的库函数nth_element(start,start+n,end);这个函数找的是[start,end)这个左闭右开区间内部第n+1大的数,感觉这个题就是为这个函数设计的。因为他是把拍完序以后应该在下标为n的位置的数归位,n左边的数比他小,右边的数比他大(不完全快排),这个题还有一个优化的地方,就是减少排序区间。我们先处理大的询问再处理小的询问。我举个例子,比如54321,现在我要求第5小的数,是5,处理完以后数组可能是43215,5是归位的但是其他数还是乱序的。然后我再在[0,4)这个区间内部去找第4小的数,和我原来要在[0,5)这个区间内部去找第四小的数结果是一样的。这样做的优点在于我们逐渐减少了,处理的区间加快了速度。这个题是个暴力题,如果没有这个优化是会超时的。

代码:

 //Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define da cout<<da<<endl
#define uoutput(a,i,l,r) for(int i=l;i<r;i++) if(i==l) cout<<a[i];else cout<<" "<<a[i];cout<<endl;
#define doutput(a,i,l,r) for(int i=r-1;i>=0;i--) if(i==r-1) cout<<a[i];else cout<<" "<<a[i];cout<<endl;
const long long N=1e7+;
using namespace std;
typedef long long LL;
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;
}
unsigned num[N];
unsigned ans[N],ca=;
pair<int,int>q[+];
int cmp(pair<int,int>a,pair<int,int>b){
return a.first<b.first;
}
int main() {
ios::sync_with_stdio(false);cin.tie();
unsigned n,m;
while(cin>>n>>m>>x>>y>>z){
for(int i=;i<n;i++) num[i]=rng61();
for(int i=;i<m;i++) {cin>>q[i].first;q[i].second=i;}
sort(q,q+m,cmp);//从小到大排序
q[m].first=n;
q[m].second=m;
for(int i=m-;i>=;i--){
//我们知道q[i+1].f是大于q[i].f的所以我们根据这个性质
//我们每次在[0,q[i+1].f)这个区间里面去找第q[i].f+1大的的数
//我们还需要知道nth_element这个函数是把第n+1大的数放在n的下标里面
nth_element(num,num+q[i].first,num+q[i+].first);
ans[q[i].second]=num[q[i].first];
}
cout<<"Case #"<<++ca<<":";
for(int i=;i<m;i++) cout<<" "<<ans[i];
cout<<endl;
}
return ;
}

2017 Multi-University Training Contest - Team 1—HDU6040的更多相关文章

  1. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  3. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  4. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  5. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  8. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. AppModify修改app.config

    public class AppModify { /// <summary> /// 依据连接串名字connectionName返回数据连接字符串 /// </summary> ...

  2. 【Android】15.2 广播

    分类:C#.Android.VS2015: 创建日期:2016-02-29 一.简介 Android系统和你自己编写的应用程序都可以通过Indent发送和接收广播信息.广播的内容既可以是自定义的信息, ...

  3. HDOJ 5289 Assignment 单调队列

    维护一个递增的和递减的单调队列 Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  4. 每日英语:Rethinking How We Watch TV

    To understand how much television could soon change, it helps to visit an Intel Corp. division here ...

  5. 每日英语:Risk-Averse Culture Infects U.S. Workers, Entrepreneurs

    Americans have long taken pride on their willingness to bet it all on a dream. But that risk-taking ...

  6. Python正则表达式中的re.S的作用

    在Python的正则表达式中,有一个参数为re.S.它表示“.”(不包含外侧双引号,下同)的作用扩展到整个字符串,包括“\n”.看如下代码: import re a = '''asdfhellopas ...

  7. Lucene:基于Java的全文检索引擎简介 (zhuan)

    http://www.chedong.com/tech/lucene.html ********************************************** Lucene是一个基于Ja ...

  8. 为什么 Windows API 使用 stdcall 调用约定?

    作者:知乎用户链接:https://www.zhihu.com/question/31453641/answer/52001143来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  9. st16c554

    /* * st16c554.c * * TWO ST16C554 driver for AMCC PPC405EP * * Author: Li Zhi You/Zhu jiang <godis ...

  10. am335x -- kio 控制接口

    //example #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include < ...