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.

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 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 }
时间: 2024-12-21 02:13:57

HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1的相关文章

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(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

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 6170 - Two strings | 2017 ZJUT Multi-University Training 9

/* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问两串是否匹配 分析: dp[i][j] 代表B[i] 到 A[j]全部匹配 然后根据三种匹配类型分类讨论,可以从i推到i+1 复杂度O(n^2) */ #include <bits/stdc++.h> using namespace std; const int N = 2505; int t;

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 6168 - Numbers | 2017 ZJUT Multi-University Training 9

/* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢慢筛 */ #include <bits/stdc++.h> using namespace std; const int N = 125250; int n, s[N]; int a[N], cnt; multiset<int> st; multiset<int>::it

HDU 6058 Kanade&#39;s sum —— 2017 Multi-University Training 3

Kanade's sum Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2512    Accepted Submission(s): 1045 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest eleme

HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)

题意:构造出n个数 这n个数取值范围0-L,这n个数中存在取一些数之和等于k,则这样称为一种方法.给定n,k,L,求方案数. 思路:装压 每位 第1为表示这种方案能不能构成1(1表示能0表示不能)  第2为表示能不能构成2 ...  这样用d[1<<n] 的DP  像背包那样背 n次就可以 最后状态中第k位为1的就可以加上方法数. #include<cstring> #include<cstdio> #include<cmath> #include <