码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 6040 -Hints of sd0061(STL)

时间:2018-08-05 11:56:03      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:play   www.   output   ios   make   rda   result   有序   nod   

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+bjbk is satisfied if bibjbi<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. (1n107,1m100)

The second line contains m integers, the i-th of which is the number bi of the i-th hint. (0bi<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: yyym" in one line (without quotes), where x indicates the case number starting from 1 and y(1im) 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+bjbk is satisfied if bibjbi<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
View Code

 

hdu 6040 -Hints of sd0061(STL)

标签:play   www.   output   ios   make   rda   result   有序   nod   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!