http://poj.org/problem?id=1068
View Code
1 #include<stdio.h> 2 #include<string.h> 3 int stack[20001],top,b[10001]; 4 void inst(int x,int y) 5 { 6 int i; 7 for(i = top+1 ; i <= top+(x-y) ; i++) 8 stack[i] = 1; 9 top = top+x-y+1; 10 stack[i] = 0; 11 b[x] = top; 12 } 13 int main() 14 { 15 int i,j,k,a[21],t,g,n; 16 scanf("%d", &t); 17 while(t--) 18 { 19 top = 0; 20 scanf("%d", &n); 21 a[0]=0; 22 for(i = 1;i <= n ;i++) 23 { 24 scanf("%d",&a[i]); 25 inst(a[i],a[i-1]); 26 } 27 k = 0; 28 for(i = 1 ; i <= n ; i++) 29 { 30 g = 1; 31 for(j = b[a[i]]-1 ; j >= 1; j--) 32 { 33 34 if(stack[j]==1) 35 { 36 stack[j]=2; 37 if(k != 0) 38 printf(" "); 39 printf("%d",g); 40 k++; 41 break; 42 } 43 else 44 if(stack[j]==2) 45 g++; 46 } 47 } 48 printf("\n"); 49 50 } 51 return 0; 52 }