hdu 6040 -Hints of sd0061(STL)

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

题意:输入n,m,A,B,C 由ABC和题中提供的函数可以 得到n个数的数组a[n](就是for循环跑n此题给函数就可以了) ,然后输入m个数 表示 数组b[m],现在对于每个b[i]输出a[]数组中的第b[i]+1小的数。题中给出b[]数组的限制bi+bj≤bk is satisfied if bi≠bj, bi<bk and bj<bk;

思路:利用nth_element(a,a+k,a+n)函数,其原理类似于快拍,k项之前的都小于a[k](不一定有序),k后面的都是大于a[k],复杂度O(n)。

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6 const int N=1e7+5;
 7 unsigned x,y,z, A,B,C;
 8 unsigned a[N];
 9 struct Node
10 {
11     int x;
12     int id;
13     unsigned y;
14 }tr[105];
15 bool cmp(const Node s1,const Node s2)
16 {
17     return s1.x<s2.x;
18 }
19 bool cmp2(const Node s1,const Node s2)
20 {
21     return s1.id<s2.id;
22 }
23
24 unsigned rng61() {
25   unsigned t;
26   x ^= x << 16;
27   x ^= x >> 5;
28   x ^= x << 1;
29   t = x;
30   x = y;
31   y = z;
32   z = t ^ x ^ y;
33   return z;
34 }
35
36 int main()
37 {
38     ///cout << "Hello world!" << endl;
39     int n,m,Case=1;
40     while(scanf("%d%d%u%u%u",&n,&m,&A,&B,&C)!=EOF)
41     {
42         x = A, y = B, z = C;
43         for(int i=0;i<n;i++)  a[i]=rng61();
44         printf("Case #%d:",Case++);
45         for(int i=1;i<=m;i++) scanf("%d",&tr[i].x),tr[i].id=i;
46         sort(tr+1,tr+m+1,cmp);
47
48         int p=n;
49         for(int i=m;i>=1;i--)
50         {
51             int x = tr[i].x;
52             nth_element(a,a+x,a+p);
53             p=x;
54             tr[i].y=a[x];
55         }
56         sort(tr+1,tr+m+1,cmp2);
57         for(int i=1;i<=m;i++) printf(" %u",tr[i].y);
58         puts("");
59     }
60     return 0;
61 }//转自https://www.cnblogs.com/chen9510/p/7250651.html

原文地址:https://www.cnblogs.com/llllrj/p/9424835.html

时间: 2024-11-12 15:17:31

hdu 6040 -Hints of sd0061(STL)的相关文章

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 yea

HDU 6040 Hints of sd0061 nth_element函数

Hints of sd0061 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

HDU 6040 Hints of sd0061 思维

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6040 题目大意: 给定数组a, b.要求输出和B长度相同的数组C, C[i]为在A中排名为B[i]的数, 重新排A数组, 使得a[i]必须是a数组中第b[i]+1大的数 解题思路: 首先我们要把数组A求出来.第一想法就是最单纯的将A排个序, 然后输出A[B[i]], 自己还恬不知耻的去交了一发, 要是这都不会T, 还叫啥ACM啊...... 好吧, 我题意理解错了......自己太浮躁了, 检讨一

HDU 6040 Hints of sd0061(nth_element)

[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi<bk,bj<bk,有bi+bj<=bk [题解] 我们将所有的询问排序,我们发现倒着处理询问的时候询问区间大小下降非常快, nth_element(start,start+k,end) 可以近似O(n)查询区间中第k小的数字, 并且在处理后保证比第k小小的数字均在其前面(虽然不一定有序), 所以我

HDU 6040 stl

Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2421    Accepted Submission(s): 736 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired last yea

hdu 4941 Magical Forest(STL map &amp; 结构体运用)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 220    Accepted Submission(s): 105 Problem Description There is a forest c

HDU 2072 单词数 --- stringstream+STL

/* HDU 2072 单词数 --- stringstream+STL */ #include <cstdio> #include <iostream> #include <sstream> #include <string> #include <set> using namespace std; set<string> k; int main() { string s; while (getline(cin, s) &&a

hdu 4941 Magical Forest(STL之map应用)2014多校训练第7场

Magical Forest                                                                       Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description There is a forest can be seen as N * M grid. In this fore

第一场 B 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 ha