第一场 hdu 6040 Hints of sd0061

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 mm coming contests. sd0061 has left a set of hints for them. 

There are nn noobs in the team, the ii-th of which has a rating aiai. sd0061 prepares one hint for each contest. The hint for the jj-th contest is a number bjbj, which means that the noob with the (bj+1)(bj+1)-th lowest rating is ordained by sd0061 for the jj-th contest. 

The coach asks constroy to make a list of contestants. constroy looks into these hints and finds out: bi+bjbkbi+bj≤bk is satisfied if bibj,bi≠bj, bi<bkbi<bk and bj<bkbj<bk. 

Now, you are in charge of making the list for constroy.

InputThere are multiple test cases (about 1010). 

For each test case: 

The first line contains five integers n,m,A,B,Cn,m,A,B,C. (1n107,1m100)(1≤n≤107,1≤m≤100) 

The second line contains mm integers, the ii-th of which is the number bibi of the ii-th hint. (0bi<n)(0≤bi<n) 

The nn noobs' ratings are obtained by calling following function nn times, the ii-th result of which is aiai. 

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;
}

OutputFor each test case, output " Case #xx: y1y1 y2y2 ⋯ ymym" in one line (without quotes), where xx indicates the case number starting from 11 and yiyi (1im)(1≤i≤m) denotes the rating of noob for the ii-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个bi打印n个数中第bi+1大的数。

解题思路:对bi进行由小到大排序,然后从m到0使用nth_element进行查找,找出bi+1大的数

AC代码:


 1 #include <iostream>
 2 #include<cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 unsigned int a[10000005];
 7 struct node
 8 {
 9     int id,pos;
10     unsigned int ans;
11 }cnt[105];
12 unsigned int x,y,z;
13 unsigned int rng61() {
14   unsigned int t;
15   x ^= x << 16;
16   x ^= x >> 5;
17   x ^= x << 1;
18   t = x;
19   x = y;
20   y = z;
21   z = t ^ x ^ y;
22   return z;
23 }
24 int cmp1(const node &u,const node &v)
25 {
26     if(u.pos!=v.pos)
27     return u.pos<v.pos;
28     else
29     return u.id<v.id;
30 }
31 int cmp2(const node &u,const node &v)
32 {
33     return u.id<v.id;
34 }
35 int main()
36 {
37     int n,m,cas=0;
38     //freopen("1008.in","r",stdin);
39     //freopen("1008.out","w",stdout);
40     while(~scanf("%d%d",&n,&m))
41     {
42         cas++;
43         scanf("%u%u%u",&x,&y,&z);
44         for(int i=0;i<n;i++)
45         {
46             a[i]=rng61();
47             //printf("%d\n",a[i]);
48         }
49         for(int i=0;i<m;i++)
50         {
51             scanf("%d",&cnt[i].pos);
52             cnt[i].id=i;
53         }
54         sort(cnt,cnt+m,cmp1);
55         cnt[m].pos=n;
56         cnt[m].id=m;
57 //        for(int i=0;i<m;i++)
58 //        printf("%d %d\n",cnt[i].pos,cnt[i].id);
59         for(int i=m-1;i>=0;i--)
60         {
61             nth_element(a,a+cnt[i].pos,a+cnt[i+1].pos);
62             //printf("%d\n",a[cnt[i].pos]);
63             //printf("%d\n",a[cnt[i].pos]);
64             cnt[cnt[i].id].ans=a[cnt[i].pos];
65         }
66         printf("Case #%d:",cas);
67         for(int i=0;i<m;i++)
68         {
69             printf(" %u",cnt[i].ans);
70         }
71         printf("\n");
72     }
73     return 0;
74 }
View Code

 

posted @ 2017-07-31 12:30  Wally的博客  阅读(174)  评论(0编辑  收藏  举报