您的位置:首页 > 其它

hdu 多校联赛 Inversion

2017-08-10 15:42 411 查看


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=maxi∤jAj , i≥2.

 

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
T≤20
2≤n≤100000
1≤Ai≤1000000000
∑n≤700000

 

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<cstdio>
#include<iostream>
#include<cstring>
#include<stdlib.h>
using namespace std;
const int N=1e5+10;
struct Node
{
int val;
int pos;
}A
;

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: