标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4558 Accepted Submission(s): 2125
#include<stdio.h> #include<string.h> #define MAX 11000 int main() { int t,n,m,i,j,k; int set[MAX],a[MAX],b[MAX]; scanf("%d",&t); while(t--) { memset(set,0,sizeof(set)); scanf("%d",&n); if(n==1) { printf("1\n"); continue; } else if(n==2) { printf("1 2\n"); continue; } else if(n==3) { printf("1 2 3\n"); continue; } for(i=1;i<=n;i++) { set[i]=i; } int l=1,ok=n; while(1) { if(l&1) { k=0; memset(a,0,sizeof(a)); for(i=1;i<=n;i++) { if(i%2!=0) { a[++k]=set[i]; } else { --ok; } } //printf("%d\n",k); n=ok; memset(set,0,sizeof(set)); for(i=1;i<=k;i++) { set[i]=a[i]; } } else { m=0; memset(b,0,sizeof(b)); for(i=1;i<=n;i++) { if(i%3==0) { --ok; continue; } b[++m]=set[i]; } n=ok; //printf("%d#\n",m); memset(set,0,sizeof(set)); for(i=1;i<=m;i++) { set[i]=b[i]; } } l++; if(n<=3) break; } if(k<m) { for(i=1;i<=k;i++) { if(i==1) printf("%d",a[i]); else printf(" %d",a[i]); } printf("\n"); } else if(m<k) { for(i=1;i<=m;i++) { if(i==1) printf("%d",b[i]); else printf(" %d",b[i]); } printf("\n"); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4693918.html