Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
神奇的构造法,把这个题变成了水题,DFS会T的//贴一下DFS吧,虽然T了 #include <stdio.h> int main() { int n; while(scanf("%d",&n),n) { if(n%6!=2&&n%6!=3) { if(n%2==0) { for(int i=2;i<=n;i+=2) printf("%d ",i); for(int i=1;i<=n-3;i+=2) printf("%d ",i); printf("%d\n",n-1); } else { for(int i=2;i<=n-1;i+=2) printf("%d ",i); for(int i=1;i<=n-2;i+=2) printf("%d ",i); printf("%d\n",n); } } else { if(n%2==0) { int k=n/2; if(k%2==0) { for(int i=k;i<=n;i+=2) printf("%d ",i); for(int i=2;i<=k-2;i+=2) printf("%d ",i); for(int i=k+3;i<=n-1;i+=2) printf("%d ",i); for(int i=1;i<=k-1;i+=2) printf("%d ",i); printf("%d\n",k+1); } else { for(int i=k;i<=n-1;i+=2) printf("%d ",i); for(int i=1;i<=k-2;i+=2) printf("%d ",i); for(int i=k+3;i<=n;i+=2) printf("%d ",i); for(int i=2;i<=k-1;i+=2) printf("%d ",i); printf("%d\n",k+1); } } else { int k=(n-1)/2; if(k%2==0) { for(int i=k;i<=n-1;i+=2) printf("%d ",i); for(int i=2;i<=k-2;i+=2) printf("%d ",i); for(int i=k+3;i<=n-2;i+=2) printf("%d ",i); for(int i=1;i<=k+1;i+=2) printf("%d ",i); printf("%d\n",n); } else { for(int i=k;i<=n-2;i+=2) printf("%d ",i); for(int i=1;i<=k-2;i+=2) printf("%d ",i); for(int i=k+3;i<=n-1;i+=2) printf("%d ",i); for(int i=2;i<=k+1;i+=2) printf("%d ",i); printf("%d\n",n); } } } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator