Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
28593 LYLAKIOI 【BJ】T1 C++ 通过 100 859 MS 424 KB 1931 2024-04-27 10:16:48

Tests(100/100):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define m_p make_pair #define p1 first #define p2 second #define p_b push_back using namespace std; typedef long long ll; const int maxn=23333; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n; bool used[maxn]; ll a[maxn],b[maxn]; int P[maxn]; int st1[maxn],st2[maxn],tp1,tp2; ll f(int i,int j,int k){ return a[i]*b[j]+a[j]*b[k]+a[k]*b[i]; } bool chk(int i,int j,int k){ return f(i,j,k)>=f(k,j,i); } int g(){ int res=0; up(i,1,n-2)if(!chk(P[i],P[i+1],P[i+2]))res++; return res; } bool getperm(){ up(i,1,n)used[i]=0; P[1]=rand()%n+1,P[2]=P[1]; while(P[2]==P[1])P[2]=rand()%n+1; used[P[1]]=used[P[2]]=1; up(i,3,n){ tp1=tp2=0; up(j,1,n)if(!used[j]){ st1[++tp1]=j; if(chk(P[i-2],P[i-1],j))st2[++tp2]=j; } if(!tp2){ return 0; }else { P[i]=st2[rand()%tp2+1]; } used[P[i]]=1; }return 1; } void SA(){ /*double T=1000; while(T>1e-2){ int x=rand()%n+1,y=rand()%n+1; swap(P[x],P[y]); int qwq=g(); if(qwq<now)now=qwq; else if(exp(-(qwq-now)/T)>rand())now=qwq; else swap(P[x],P[y]); if(!now){ up(i,1,n)printf("%d%c",P[i],(i<n?' ':'\n')); exit(0); } T*=0.9997; }*/ } void slv(){ n=read();up(i,1,n)a[i]=read(),b[i]=read(); while(1){ if(getperm()){ up(i,1,n)printf("%d%c",P[i],(i<n?' ':'\n')); return; } } }int main(){srand(time(0)); // freopen("assign.in","r",stdin); // freopen("assign.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }


测评信息: