思路:
AC代码:
#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define ll long long #define endl (" ") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e5+100; const ll mod=1e9+7; struct Node{ int id, v; bool friend operator< (Node a, Node b){ return a.v>b.v; } }; Node a[N]; int n; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T; cin>>T; while(T--){ cin>>n; for(int i=1; i<=n; ++i){ cin>>a[i].v; a[i].id=i; } sort(a+1, a+1+n); for(int i=2; i<=n; ++i){ for(int j=1; j<=n; ++j){ if(a[j].id%i!=0){ if(i==2) cout<<a[j].v; else cout<<" "<<a[j].v; break; } } } cout<<endl; } return 0; } /* struct Node{ int id,v; bool friend operator< (Node a, Node b){ return a.v>b.v; } }; Node a[N],mk[N]; int n,c[N]; vector<int> vex[N]; void init(){ for(int i=2; i<N; ++i){ for(int j=1; j*j<=i; ++j){ if(i%j==0){ vex[i].pb(j); if(j!=i/j)vex[i].pb(i/j); } } } } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); init(); int T; cin>>T; while(T--){ cin>>n; for(int i=1; i<=n; ++i){ cin>>a[i].v; a[i].id=i, mk[i].id=1, mk[i].v=0, c[i]=1; } sort(a+1,a+1+n); int cnt=1; for(int i=2; i<=n; ++i){ if(a[i].v==a[i-1].v){ c[cnt]++; } else{ cnt++; } } for(int i=1; i<=n; ++i){ for(auto p : vex[a[i].id]){ if(mk[p].id==i){ mk[p].v++; if(mk[p].v>=c[i]){ mk[p].id++; mk[p].v=0; } } } } for(int i=2; i<=n; ++i){ if(i==2) cout<<a[mk[i].id].v; else cout<<" "<<a[mk[i].id].v; } cout<<endl; } return 0; } */