hdu 多校联赛 Inversion

Inversion

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


Problem Description
Give an array A, the index starts from 1.
Now we want to know  Bi=maxijAj ,  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
 

题意比较简单 在这也就不再重复 这道题出错大多是tle 其实题目已经告诉了本题的解法 反转 正着推超时 那就反过来推

ac代码:

#include
#include
#include
#include
using namespace std;
const int N=1e5+10;
struct Node
{
    int val;
    int pos;
}A[N];

int cmpDec(const void *a,const void *b)//怕超时特地用了快排 其实sort也能过
{
    return (((Node*)b)->val)-(((Node*)a)->val);
}
int main()
{
    int t;
    cin>>t;
    int n;
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            {
             scanf("%d",&A[i].val);
             A[i].pos=i;
            }
        qsort(A+1,N,sizeof(Node),cmpDec);
        for(int i=2;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(A[j].pos%i!=0)
                {
                    if(i==2)
                    {
                        printf("%d",A[j].val);
                        break;
                    }
                    else
                    {
                        printf(" %d",A[j].val);
                        break;
                    }
                }
            }
        }
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(ACM,杭电多校联赛,ACM题目解析)