zoukankan      html  css  js  c++  java
  • 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 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: yy⋯ ym" 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
  • 相关阅读:
    证券创新之翼 阿里金融云
    通过改变计算机策略来解决“只能通过Chrome网上应用商店安装该程序”的方法及模版文件下载
    VMware Workstation pro 12下载以及序列号
    Centos7下配置Tomcat7以指定(非root)身份运行
    apache2: Could not reliably determine the server's fully qualified domain name
    apache使用ssl数字证书
    苹果远程控制
    excel 组及分级显示制作教程
    Apache 性能优化
    Pigs and chickens
  • 原文地址:https://www.cnblogs.com/llllrj/p/9424835.html
Copyright © 2011-2022 走看看