提交时间:2024-04-28 08:35:16
运行 ID: 28605
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> int p[5010]; int a[5010],b[5010]; inline int f(int x,int y){ return a[x]*b[y]-a[y]*b[x]; } inline bool chk(int i,int j,int k){ return f(i,j)+f(j,k)+f(k,i)>=0; } int n; inline bool calc(){ bool res=1; for(int i=1;i<=n-2;i++) if(!chk(p[i],p[i+1],p[i+2])) swap(p[i+1],p[i+2]),res=0; return res; } int C; //inline int ti(){ // return (clock()-C)*1000/CLOCKS_PER_SEC; //} inline bool chk(){ bool res=1; for(int i=1;i<=n-2;i++) if(!chk(p[i],p[i+1],p[i+2]))res=0; return res; } signed main() { // freopen("assign.in","r",stdin); // freopen("assign.out","w",stdout); ios::sync_with_stdio(0); // C=clock(); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]>>b[i],p[i]=i; if(n<=9){ int cnt=1; for(int i=1;i<=n;i++)cnt*=i; while(cnt--){ if(chk()){ for(int i=1;i <=n;i++) cout<<p[i]<<" "; cout<<endl; return 0; } next_permutation(p+1,p+n+1); } } srand(time(0)); bool w=0; while(1){ random_shuffle(p+1,p+n+1); w=0; // int k=ti(); while(!w){ w=calc(); } if(w)break; // if(ti()>=800)break; } if(w) for(int i=1;i<=n;i++) cout<<p[i]<<" "; else cout<<-1; cout<<endl; return 0; } /* */