HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
Total Submission(s): 2297 Accepted Submission(s): 687
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.
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.
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 40551
题目大意:用题目所给的程序生成a数组,m个询问,每个询问输出a从小至大排序后第bi个数。
思路:按照题意进行排序,不过输出ai前用sort会超时,用nth_element()可以避免TLE。
AC代码:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=1e7+5; 7 unsigned n, m; 8 unsigned rat[MAXN], b[MAXN],p[MAXN], a[MAXN]; 9 unsigned x,y,z; 10 unsigned rng61() { 11 unsigned t; 12 x ^= x << 16; 13 x ^= x >> 5; 14 x ^= x << 1; 15 t = x; 16 x = y; 17 y = z; 18 z = t ^ x ^ y; 19 return z; 20 } 21 bool cmp(int s, int t) 22 { 23 return b[s]<b[t]; 24 } 25 int main() 26 { 27 int k=0; 28 while(~scanf("%d %d %u %u %u", &n, &m, &x, &y, &z)) 29 { 30 for(int i=0;i<m;i++){ 31 p[i]=i; 32 scanf("%d", b+i); 33 } 34 35 for(int i=0;i<n;i++) 36 rat[i]=rng61(); 37 sort(p, p+m,cmp); 38 b[p[m]=m]=n; 39 for(int i=m-1;i>=0;i--){ 40 if(b[p[i]]==b[p[i+1]]){ 41 a[p[i]]=a[p[i+1]]; 42 //continue; 43 } 44 nth_element(rat, rat+b[p[i]], rat+b[p[i+1]]); 45 a[p[i]]=rat[b[p[i]]]; 46 } 47 printf("Case #%d:", ++k); 48 for(int i=0;i<m;i++) 49 printf(" %u", a[i]); 50 printf("\n"); 51 } 52 }
以上是关于HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1的主要内容,如果未能解决你的问题,请参考以下文章
HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1