标签:
Description
Input
Output
Sample Input
Sample Output
1 #include <stdio.h> 2 3 int main() 4 { 5 int a[15000],i,k,n,t,head,tail,count; 6 7 while(scanf("%d",&n)!=EOF) 8 { 9 for(k=0;k<n;k++) 10 { 11 scanf("%d",&t); 12 if(t==1) 13 {printf("1\n");continue;} 14 else if(t==2) 15 {printf("1 2\n");continue;} 16 else if(t==3) 17 {printf("1 2 3\n");continue;} 18 19 for(i=0;i<=t;i++) 20 a[i]=i; 21 head = 1; 22 tail = t+1; 23 while(tail-head>3) 24 { 25 count = tail-1; 26 while(head<=count) 27 { 28 a[tail]=a[head]; 29 tail++; 30 head+=2; 31 } 32 head = count+1; 33 if(tail-head>3) 34 { 35 count = tail-1; 36 while(head<=count) 37 { 38 a[tail]=a[head]; 39 tail++; 40 head++; 41 if(head<=count) 42 { 43 a[tail]=a[head]; 44 tail++; 45 head+=2; 46 } 47 } 48 head = count+1; 49 continue; 50 } 51 } 52 count = tail - head; 53 for(i=0;i<count;i++) 54 { 55 if(i!=count-1) 56 printf("%d ",a[head+i]); 57 else 58 printf("%d\n",a[head+i]); 59 } 60 } 61 } 62 return 0; 63 }
标签:
原文地址:http://www.cnblogs.com/yoghurtman/p/4665538.html