HDOJ 1069_大二寫
阿新 • • 發佈:2018-11-01
pri \n bsp line for fine 核心部分 mes long
AC代碼:
//HDOJ 1069 #include <iostream> #include <cstdio> #include <algorithm> #define Max 100 using namespace std; struct dimensinos { int l; int w; int d; long int max_deadline_unit; }block[Max]; bool compare(dimensinos a, dimensinos b) { return a.l*a.w > b.l*b.w ; }int main(void) { freopen("in.txt","r",stdin); int N, count = 1; while(scanf("%d",&N) && N) { int x, y, z; long int max_universe; for(int i = 1; i <= N * 3; i++) { scanf("%d%d%d", &x, &y, &z); block[i].l= x; block[i].w = y; block[i].d = z; block[++i].l = z; block[i].w = x; block[i].d = y; block[++i].l = y; block[i].w = z; block[i].d= x; } sort(block + 1, block + 1 + N * 3, compare); //面積從大到小排序 //算法的核心部分 block[1].max_deadline_unit = block[1].d; max_universe = block[1].max_deadline_unit; for(int i = 2; i <= 3*N; i++) { block[i].max_deadline_unit = block[i].d; for(int j = i-1; j >= 1; j--) { if(!((block[i].l<block[j].l && block[i].w<block[j].w)||(block[i].l<block[j].w && block[i].w<block[j].l))) { continue; } if(block[i].max_deadline_unit < block[i].d + block[j].max_deadline_unit) block[i].max_deadline_unit = block[i].d + block[j].max_deadline_unit; } if(max_universe < block[i].max_deadline_unit) max_universe = block[i].max_deadline_unit; } printf("Case %d: maximum height = %ld\n", count, max_universe); count++; } fclose(stdin); system("pause"); return 0; }
HDOJ 1069_大二寫