HDOJ 1069
此题的要求:
1、下方积木的面积要大于上方的面积;
2、下方积木的长和宽要大于上方的长和宽
AC代码:
#include <iostream> #include <algorithm> #define Max 95 using namespace std; struct st { int x,y,z,max; }a[Max]; bool compare(st a,st b) { return a.x * a.y >b.x * b.y ; } int main(void) { freopen("in.txt","r",stdin); int n,count=1; while(cin>>n&&n) { int i,j,x,y,z; for(i=0;i<3*n;i++) { cin>>x>>y>>z; a[i].x=x; a[i].y=y; a[i].z=z; i++; a[i].x=y; a[i].y=z; a[i].z=x; i++; a[i].x=z; a[i].y=x; a[i].z=y; } sort(a,a+3*n,compare); a[0].max=a[0].z; int maxx=a[0].z; for(i=1;i<3*n;i++) { a[i].max=a[i].z; for(j=i-1;j>=0;j--) { if(!(a[i].x<a[j].x&&a[i].y<a[j].y||a[i].x<a[j].y&&a[i].y<a[j].x)) continue; if(a[i].max<a[i].z+a[j].max) a[i].max=a[i].z+a[j].max; } if(maxx<a[i].max) maxx=a[i].max; } cout<<"Case "<<count<<": maximum height = "<<maxx<<endl; count++; } fclose(stdin); return 0; }