题目链接

 

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 k.

Now, you are in charge of making the list for constroy.
 
Input
There are multiple test cases (about i.

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 #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] ,然后输入m个数 表示 数组b[m],现在对于每个b[i]输出a[]数组中的第b[i]+1小的数。题中给出b[]数组的限制k;
 
思路:可以发现b[]数组不是很大,对于每个b[i]找a[]数组的第b[i]+1的数时,可以使用nth(a,a+p,a+n) 这个STL函数,进行一次o(n)的排序,使得a[p]之前的数均小于a[p],a[p]之后的数均大于a[p],所以a[p]即为我们要的数。在对每个b[]元素操作时,可以对b[]排序,从大到小进行计算,以为之前排序的右半部分不必再进行排序,这样会减少很多计算量。
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e7+5;
unsigned x,y,z, A,B,C;
unsigned a[N];
struct Node
{
    int x;
    int id;
    unsigned y;
}tr[105];
bool cmp(const Node s1,const Node s2)
{
    return s1.x<s2.x;
}
bool cmp2(const Node s1,const Node s2)
{
    return s1.id<s2.id;
}

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;
}

int main()
{
    ///cout << "Hello world!" << endl;
    int n,m,Case=1;
    while(scanf("%d%d%u%u%u",&n,&m,&A,&B,&C)!=EOF)
    {
        x = A, y = B, z = C;
        for(int i=0;i<n;i++)  a[i]=rng61();
        printf("Case #%d:",Case++);
        for(int i=1;i<=m;i++) scanf("%d",&tr[i].x),tr[i].id=i;
        sort(tr+1,tr+m+1,cmp);

        int p=n;
        for(int i=m;i>=1;i--)
        {
            int x = tr[i].x;
            nth_element(a,a+x,a+p);
            p=x;
            tr[i].y=a[x];
        }
        sort(tr+1,tr+m+1,cmp2);
        for(int i=1;i<=m;i++) printf(" %u",tr[i].y);
        puts("");
    }
    return 0;
}

 

相关文章:

  • 2022-01-27
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
猜你喜欢
  • 2021-08-06
  • 2021-08-30
  • 2022-12-23
  • 2021-06-14
  • 2021-06-22
  • 2022-03-09
  • 2021-09-11
相关资源
相似解决方案