【HDU 6040 Hints of sd0061】 思维 & STL

来源:互联网 发布:淘宝爱玩电玩数码店 编辑:程序博客网 时间:2024/06/13 21:22

Hints of sd0061

Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2379 Accepted Submission(s): 721

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

#include<bits/stdc++.h>using namespace std;struct node{    int b,o;    unsigned a;}st[110];const int MAX = 1e7 + 10;unsigned x,y,z,a[MAX];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;}bool cmp(node i,node j) { return i.b < j.b; }bool cnp(node i,node j) { return i.o < j.o; }int main(){    int n,m,nl = 0;    while(~scanf("%d %d %u %u %u",&n,&m,&x,&y,&z)){        for(int i = 0; i < n; i++) a[i] = rng61();        for(int i = 0; i < m; i++) scanf("%d",&st[i].b),st[i].o = i;        sort(st,st + m,cmp);        int pl = n;        for(int i = m - 1; i >= 0; i--){            int b = st[i].b;            nth_element(a,a + b,a + pl); // 在 a  ~ a + pl 数组里找到第 b + 1 小的数            pl = b;            st[i].a = a[b];        }        sort(st,st + m,cnp);        printf("Case #%d:",++nl);        for(int i = 0; i < m; i++) printf(" %u",st[i].a);        puts("");    }    return 0;}
原创粉丝点击