hdu 6098 Inversion

Posted -凡-尘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 6098 Inversion相关的知识,希望对你有一定的参考价值。

Inversion

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 339    Accepted Submission(s): 230

Problem Description
Give an array A, the index starts from 1.
Now we want to know Bi=max {  A |  i?j  }, i2.
 
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with one integer n : the size of array A.
Next one line contains n integers, separated by space, ith number is Ai.

Limits
T20
2n100000
1Ai1000000000
n700000

 

Output
For each test case output one line contains n-1 integers, separated by space, ith number is Bi+1.
 
 
Sample Input
2
4
1 2 3 4
4
1 4 2 3
 
Sample Output
3 4 3
2 4 4

 

Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6107 6106 6105 6104 6103 
 

题目大意:

给你一个数组 a ,让你求出数组 b 。b[ i ] 表示 a 数组中下标不能被 i 整除的数里面的最大值。

题解:

把a数组开个结构体,存入值和标号,按值从大到小排序,然后从最大的开始询问起,如果a[i].id 此时的下标不能被b的下标 j 整除,则给 b[j] 赋值a[i].k

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<bits/stdc++.h>

using namespace std;

 long long b[100005];
 int T,n;

struct node
{
    long long k;
    int id;
}a[100005];
bool cmp(node a,node b)
{
    return a.k>b.k;
}

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i].k);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        int tmp=n-1;
        for(int i=1;i<=n && tmp>0;i++)
        {
            for(int j=2;j<=n && tmp>0;j++)
            {
                if (b[j]==0 && a[i].id%j!=0)
                    b[j]=a[i].k,tmp--;
            }
        }
        for(int i=2;i<=n;i++)
        {
            if (i-2) printf(" ");
            printf("%d",b[i]);
        }
        printf("\n");
    }
    return 0;
}

 

以上是关于hdu 6098 Inversion的主要内容,如果未能解决你的问题,请参考以下文章

hdu6098[RMQ+筛法] 2017多校6

HDU5497 Inversion

HDU 1394 - Minimum Inversion Number

HDU 4911Inversion

hdu 1394 Minimum Inversion Number

HDU4911:Inversion