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;
}
相关文章推荐
- HDU6098 Inversion(RMQ,2017 HDU多校联赛 第6场)
- 2016多校联赛4A Another Meaning(hdu 5763)
- HDU 4335What is N?2012多校联赛第四场(欧拉函数+坑数据)
- hdu 4614 多校联赛第二场 1004题
- hdu 多校联赛 Rikka with Competition
- HDU6095 Rikka with Competition(水题,2017 HDU多校联赛 第5场)
- 2017 多校训练第六场 HDU 6098 Inversion
- 2017 杭电多校联赛第二场 1001 Is Derek lying? HDU 6045
- hdu 4911 Inversion(归并排序求逆序对数)2014多校训练第5场
- hdu 6130 Kolakoski(多校联赛)
- HDU 4339 Query2012多校联赛第四场I题(set或者线段树,下面是set解法)
- HDU 2017 多校联赛3 1008 RXD and math
- HDU 6069 Counting Divisors 【2017多校联赛4】
- hdu 多校联赛 Counting Divisors
- HDU 5358 · First One【尺取法】【读题】【多校联赛】
- HDU6092 Rikka with Subset(01背包,2017 HDU多校联赛 第5场)
- [2015hdu多校联赛补题]hdu5384 Danganronpa
- HDU 2822 多校联赛1
- HDU6168 Numbers(模拟,2017 HDU多校联赛 第9场)
- hdu 6097 Mindis(多校联赛)