1 条题解
-
0
C :
#include "stdio.h" void rank(int *x,int *y,int *z) { int t; if(*x>*y) t=*x,*x=*y,*y=t; if(*y>*z) t=*z,*z=*y,*y=t; if(*x>*y) t=*x,*x=*y,*y=t; } int main() { int n; int a[100],b[100],h[100]; int H[100],max; int x,y,z; int i,j; int t; int m; scanf("%d",&n); m=1; while(n) { j=1; for(i=0;i<n;i++) { scanf("%d%d%d",&x,&y,&z); rank(&x,&y,&z); a[j]=x,b[j]=y,h[j]=z; j++; a[j]=y,b[j]=z,h[j]=x; j++; a[j]=x,b[j]=z,h[j]=y; j++; } n=j-1; for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) if(a[i]<a[j]) { t=a[i],a[i]=a[j],a[j]=t; t=b[i],b[i]=b[j],b[j]=t; t=h[i],h[i]=h[j],h[j]=t; } } memset(H,0,sizeof(H)); for(i=1;i<=n;i++) { max=0; for(j=i-1;j>0;j--) if(a[i]<a[j]&&b[i]<b[j]&&max<H[j]) max=H[j]; H[i]=h[i]+max; } max=0; for(i=1;i<=n;i++) if(max<H[i]) max=H[i]; printf("Case %d: maximum height = %d\n",m,max); scanf("%d",&n); m++; } return 0; }
C++ :
#include<cstdio> #include<algorithm> using namespace std; struct BOX { int x,y,z; }box[180]; void f(int k,int x,int y,int z) { box[k].x=x; box[k].y=y; box[k].z=z; } bool cmp(BOX a,BOX b) { return a.x>b.x; } int main() { int n,i,j,x,y,z,k,h[180],maxi,ans,c=0; while(scanf("%d",&n)!=EOF,n) { for(k=i=0;i<n;i++) { scanf("%d%d%d",&x,&y,&z); f(k++,x,y,z); f(k++,y,x,z); f(k++,x,z,y); f(k++,z,x,y); f(k++,y,z,x); f(k++,z,y,x); } n*=6; sort(box,box+n,cmp); for(i=0;i<n;i++) h[i]=box[i].z; for(ans=i=0;i<n;i++) { for(maxi=0,j=i-1;j>=0;j--) if(box[i].x<box[j].x&&box[i].y<box[j].y&&maxi<h[j]) maxi=h[j]; h[i]+=maxi; if(ans<h[i]) ans=h[i]; } printf("Case %d: maximum height = %d\n",++c,ans); } return 0; }
Java :
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int rowIndex = 1; while (true) { int n = sc.nextInt(); if (n == 0) { break; } Block[] blocks = new Block[n * 6]; int[] h = new int[blocks.length]; int index = 0; int result = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); int z = sc.nextInt(); blocks[index++] = new Block(x, y, z); blocks[index++] = new Block(y, x, z); blocks[index++] = new Block(x, z, y); blocks[index++] = new Block(z, x, y); blocks[index++] = new Block(y, z, x); blocks[index++] = new Block(z, y, x); } Arrays.sort(blocks); for (int i = 0; i < blocks.length; i++) { h[i] = blocks[i].z; } for (int i = 0; i < blocks.length; i++) { int maxi = 0; for (int j = i - 1; j >= 0; j--) { if (blocks[i].x > blocks[j].x && blocks[i].y > blocks[j].y && maxi < h[j]) { maxi = h[j]; } } h[i] += maxi; if (result < h[i]) { result = h[i]; } } System.out.format("Case %d: maximum height = %d\n", rowIndex++, result); } sc.close(); } static class Block implements Comparable<Block> { int x, y, z; Block(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } @Override public int compareTo(Block o) { return x - o.x; } } }
- 1
信息
- ID
- 1678
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者