HDU 6040 Hints of sd0061 stl
来源:互联网 发布:学编程从什么开始学 编辑:程序博客网 时间:2024/06/14 02:38
Hints of sd0061
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2301 Accepted Submission(s): 689
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 aren 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 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.
There are
The coach asks constroy to make a list of contestants. constroy looks into these hints and finds out:
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 integersn,m,A,B,C . (1≤n≤107,1≤m≤100)
The second line containsm integers, the i -th of which is the number bi of the i -th hint. (0≤bi<n)
Then noobs' ratings are obtained by calling following function n times, the i -th result of which is ai .
For each test case:
The first line contains five integers
The second line contains
The
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 10 1 22 2 2 2 21 1
Sample Output
Case #1: 1 1 202755Case #2: 405510 405510
题意:算n次那个函数得到a数组 每次询问第b[i]大的
题解:预处理后对b数组排序然后用nth_element()就好了
因为bi+bj<=bk
所以下降速度很快
注意nth_element()第二个参数是n-1 n是第n大的
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;unsigned x,y,z;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;}unsigned a[10000007],ans[105];int b[105],pos[105];bool cmp(int i,int j){ return b[i]<b[j];}int main(){ int cas=1,i; unsigned A,B,C; int n,m; while(scanf("%d%d%u%u%u",&n,&m,&A,&B,&C)!=EOF){ x=A; y=B; z=C; for(i=1;i<=m;i++){ scanf("%d",&b[i]); // b[i]++; pos[i]=i; } sort(pos+1,pos+1+m,cmp); for(i=1;i<=n;i++)a[i]=rng61(); b[m+1]=n; pos[m+1]=m+1; printf("Case #%d:",cas++); for(i=m;i>=1;i--){ nth_element(a+1,a+1+b[pos[i]],a+1+b[pos[i+1]]); ans[pos[i]]=a[b[pos[i]]+1]; } for(i=1;i<=m;i++)cout<<" "<<ans[i]; printf("\n"); } return 0;}
阅读全文
0 0
- HDU 6040 Hints of sd0061 STL
- hdu 6040 Hints of sd0061(STL)
- hdu 6040 Hints of sd0061(STL)
- HDU 6040 Hints of sd0061 stl
- 【HDU 6040 Hints of sd0061】 思维 & STL
- HDU 6040 Hints of sd0061
- [HDU]-6040 Hints of sd0061
- HDU 6040 Hints of sd0061
- HDU-6040 Hints of sd0061
- hdu 6040 Hints of sd0061
- hdu 6040 Hints of sd0061
- hdu 6040 Hints of sd0061【STL线性排序函数】
- HDU 6040 Hints of sd0061(STL nth_element函数)
- 【多校训练】hdu 6040 Hints of sd0061 STL
- Hints of sd0061 HDU
- HDU 6040 Hints of sd0061 (技巧)
- hdu 6040 Hints of sd0061(nth_element)
- HDU 6040 Hints of sd0061(nth_element)
- python的type 和object
- Docker--I'm here(二)思想
- ZooKeeper 学习 (二) ZAB协议简单总结
- POJ1984 Navigation Nightmare(并查集)
- Java 内部类原理解析
- HDU 6040 Hints of sd0061 stl
- Java-synchronize和lock详解(转)
- oop
- POJ3041:Asteroids(二分图匹配)
- HDU 6035 Colorful Tree
- JDK源码分析之主要阻塞队列实现类LinkedBlockingQueue
- 杂记-路由器上网设置:输入路由器设置网址却登陆至猫
- 最长公共子序列
- MyISAM存储引擎