Monkey and Banana

?? 【Monkey and Banana】http://acm.hdu.edu.cn/showproblem.php?pid=1069
#include
#include
#define max(x,y) x>y?x:y
int main()
{
int num,t,i,j,k,a[3],count,maxsum[1000],max,sum,f=0;
struct block
{
int x;
int y;
int z;
}cube[1000];
while(scanf("%d",&num),num)
{
count=0;
for(i=0; i{
scanf("%d%d%d",&a[0],&a[1],&a[2]);
for(j=0; j<2; j++)
for(k=0; k<2-j; k++)
if(a[k]>a[k+1])
{
t=a[k];
a[k]=a[k+1];
a[k+1]=t;
}
cube[count].x=a[0];
cube[count].y=a[1];
cube[count].z=a[2];
count++;
cube[count].x=a[0];
cube[count].y=a[2];
cube[count].z=a[1];
count++;
cube[count].x=a[1];
cube[count].y=a[2];
cube[count].z=a[0];
count++;
}
for(i=0; ifor(j=0; j{
if(cube[j].x>cube[j+1].x)
{
t=cube[j].x;
cube[j].x=cube[j+1].x;
cube[j+1].x=t;
t=cube[j].y;
cube[j].y=cube[j+1].y;
cube[j+1].y=t;
t=cube[j].z;
cube[j].z=cube[j+1].z;
cube[j+1].z=t;
}
if(cube[j].x==cube[j+1].x && cube[j].y>cube[j+1].y)
{
t=cube[j].x;
cube[j].x=cube[j+1].x;
cube[j+1].x=t;
t=cube[j].y;
cube[j].y=cube[j+1].y;
cube[j+1].y=t;
t=cube[j].z;
cube[j].z=cube[j+1].z;
cube[j+1].z=t;
}
}
for(i=0; i{
maxsum[i]=cube[i].z;
}
for(i=0; i{
max=0;
for(j=0; jif(cube[j].xmax)
max=maxsum[j];
maxsum[i]=maxsum[i]+max;
}
sum=0;
for(i=0; iif(maxsum[i]>sum)
sum=maxsum[i];
printf("Case %d: maximum height = %d\n",++f,sum);
}
return 0;
}


    推荐阅读