/* University of Ulm Programming Contest 1996 Problem B : Babylon Implementation : Mark Dettinger */ #include #include #define max(a,b) ((a)>(b)?(a):(b)) typedef struct {int x; int y; int z;} block; block b[1200]; /* array to store the dimensions of the blocks */ int h[1200]; /* h[i] = height of the tallest tower with block i on top */ int blockcmp (const void* a, const void* b) /* comparison function for block sort */ { return ((block*)b)->x - ((block*)a)->x; } main() { FILE* input = fopen("babylon.in","r"); int i,j,n,x,y,z,height; int set = 0; /* number of completed test cases */ while (1) { /* 1. Read Input */ fscanf(input,"%d",&n); if (n==0) break; for (i=0; ib[i].x && b[j].y>b[i].y && h[j]>height) height = h[j]; h[i] = height+b[i].z; } /* 4. Now the desired result is the maximum value in array h */ height = h[0]; for (i=1; i<6*n; i++) height = max(height,h[i]); printf("Case %d: maximum height = %d\n",++set,height); } fclose(input); return 0; }