• 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 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 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("
    ");
    51     }
    52 }
  • 相关阅读:
    思路不够清晰
    深思不够
    [Android学习笔记]理解焦点处理原理的相关记录
    移动端自动化测试(二)之 Appium常用的API(python)函数介绍
    移动端自动化测试(一)之 Appium+Pyhton环境准备篇
    如何修改上线网站
    sublime如何自动保存
    自动化元素定位
    OC 字典 存储联系人信息 求大神优化代码
    我的第一个字典-Dictionary
  • 原文地址:https://www.cnblogs.com/MasterSpark/p/7265938.html
Copyright © 2020-2023  润新知