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

HDU 6040 Hints of sd0061 nth_element函数

时间:2017-08-05 11:07:54      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:its   ram   element   second   with   center   tip   ica   ati   

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 in the team, the i-th of which has a rating aisd0061 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 bibj, 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(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 #xy1 y2 ? ym" in one line (without quotes), where x indicates the case number starting from 1 and yi (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次第k小

题解:

  nth_element

  表示在数组A的[0,n-1]中找到第k小的并放在第k个位置,并且前k-1个位置均为小于A[k]的数

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 1e7+10, M = 1e3+20,inf = 2e9;

unsigned x,y,z;
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;
}
struct ss{
    int id,x;
    bool operator<(const ss& r) const{
        return x < r.x;
    }
}b[N];
int n,m;
unsigned ans[N],a[N];
int main() {
    int cas = 1;
    while(scanf("%d%d%u%u%u",&n,&m,&x,&y,&z)!=EOF) {
        for(int i = 1; i <= m; ++i)
            scanf("%d",&b[i].x),b[i].id = i;
        for(int i = 0; i < n; ++i) a[i] = rng61();
        sort(b+1,b+m+1);
        b[m+1].x = n;
        for(int i = m; i >= 1; --i) {
            nth_element(a,a+b[i].x,a+b[i+1].x);
            ans[b[i].id] = a[b[i].x];
        }
        printf("Case #%d: ",cas++);
        for(int i = 1; i < m; ++i) printf("%u ",ans[i]);
        printf("%u\n",ans[m]);
    }
}

 

HDU 6040 Hints of sd0061 nth_element函数

标签:its   ram   element   second   with   center   tip   ica   ati   

原文地址:http://www.cnblogs.com/zxhl/p/7289293.html

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