Chinaunix首页 | 论坛 | 博客

Lzy

  • 博客访问: 215958
  • 博文数量: 56
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 675
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-27 15:50
文章分类

全部博文(56)

文章存档

2014年(56)

我的朋友

分类: C/C++

2014-11-24 15:40:23


Monkey and Banana


点击(此处)折叠或打开
  1. /*

  2. #include<stdio.h>
  3. #include<string.h>
  4. struct Box{
  5.     int x;
  6.     int y;
  7.     int z;
  8.     int area;
  9. }box[91];
  10. void change(int &a,int &b)
  11. {
  12.     int temp;
  13.     temp=a;a=b;b=temp;
  14. }
  15. void cmp(int &x,int &y,int &z)
  16. {
  17.     if(x<y)change(x,y);
  18.     if(x<z)change(x,z);
  19.     if(z>y)change(z,y);
  20. }
  21. int cmp2(int n)
  22. {
  23.     Box temp;
  24.     int i,j;
  25.     for(i=0;i<=n;i++)
  26.     {
  27.         for(j=1;j<n-i;j++)
  28.            if(box[j].area<box[j+1].area)
  29.            {
  30.               temp=box[j];box[j]=box[j+1];box[j+1]=temp;
  31.            }
  32.     }
  33. }
  34. int main()
  35. {
  36.     int n,i,j;
  37.     int a,b,c;
  38.     int dp[91],big=0,len,test=1;
  39.     while(scanf("%d",&n)&&n!=0)
  40.     {
  41.         for(i=0,j=0;i<n;i++)
  42.         {
  43.             scanf("%d%d%d",&a,&b,&c);cmp(a,b,c);
  44.             box[++j].x=a;box[j].y=b;box[j].z=c;box[j].area=a*b;
  45.             if(a!=b)
  46.             {
  47.               box[++j].x=a;box[j].y=c;box[j].z=b;box[j].area=a*c;
  48.               box[++j].x=b;box[j].y=c;box[j].z=a;box[j].area=b*c;
  49.             }
  50.         }
  51.         len=j;
  52.         cmp2(len);
  53.      for(i=1;i<=len;i++)
  54.         dp[i]=box[i].z;
  55.       for(i=1;i<=len;i++)
  56.       {
  57.         for(j=1;j<i;j++)
  58.         {

  59.             if(box[i].x<box[j].x&&box[i].y<box[j].y)
  60.                 dp[i]=dp[i]>(dp[j]+box[i].z)?dp[i]:(dp[j]+box[i].z);
  61.         }
  62.         if(big<dp[i])big=dp[i];
  63.     }
  64.     printf("Case %d: maximum height = %d\n",test++,big);
  65.     big=0;
  66.     }
  67. }
  68. */



  69. //#define local

  70. #include <iostream>
  71. #include <stdio.h>
  72. #include <memory.h>
  73. #include <algorithm>

  74. using namespace std;

  75. typedef struct box
  76. {
  77.     int l;
  78.     int w;
  79.     int h;
  80. }box;

  81. int re[1000][1000];
  82. box t[1000];
  83. int nb = 0;

  84. int cmp1(const int a, const int b)
  85. {
  86.     return a>b;
  87. }

  88. void fun(int q[])
  89. {
  90.     sort(q,q+3,cmp1);


  91.         nb++;
  92.         t[nb].l = q[0];
  93.         t[nb].w = q[1];
  94.         t[nb].h = q[2];
  95.         nb++;
  96.         t[nb].l = q[1];
  97.         t[nb].w = q[2];
  98.         t[nb].h = q[0];
  99.         nb++;
  100.         t[nb].l = q[0];
  101.         t[nb].w = q[2];
  102.         t[nb].h = q[1];   //一直WA,后来大神提点原来这里错了

  103. }

  104. int cmp2(const box a,const box b)
  105. {
  106.     if(a.l == b.l)
  107.         return a.w > b.w;
  108.     return a.l > b.l;
  109. }

  110. int main()
  111. {
  112.     int n;
  113.     int i,j,k;
  114.     int a[3];
  115.     int ca = 0;

  116.     int sum = 0;
  117. // int next = 0;
  118. #ifdef local
  119.     freopen("in.txt","r",stdin);
  120. #endif // local



  121.     while(scanf("%d",&n)!=EOF && n!=0)
  122.     {
  123.         ca++;
  124.         nb = 0;
  125.         sum = 0;
  126.         memset(t,0,sizeof(box)*1000);
  127.         memset(re,0,sizeof(int)*1000000);

  128.         for(i = 0; i < n; i++)
  129.         {
  130.             scanf("%d%d%d",&a[0],&a[1],&a[2]);
  131.             fun(a);
  132.         }
  133.         sort(t+1,t+nb+1,cmp2);

  134.         for(i = 1; i<= nb; i++)
  135.         {
  136.             re[nb][i] = t[i].h;

  137.         }

  138.         for(i = nb - 1; i >= 1; i--)//第i层,又顶开始算
  139.         {
  140.             for(k = 1; k <= nb; k++) //第k个
  141.             {
  142.                 for(j = k+1;j <= nb; j++) //与下一层的累加,求最大
  143.                 {
  144.                     if(t[k].w > t[j].w && t[k].l > t[j].l)
  145.                     {
  146.                          re[i][k] = max(re[i][k],re[i+1][j] + t[k].h);
  147.                     }
  148.                 }
  149.             }
  150.         }
  151.         for(i = 1; i <= nb; i++)
  152.         {
  153.             for(j = 1; j <= nb; j++)
  154.             {
  155.                 if(re[i][j] > sum)
  156.                     sum = re[i][j];
  157.             }
  158.         }

  159.         printf("Case %d: maximum height = %d\n",ca,sum);
  160.     }
  161.     return 0;
  162. }

阅读(1354) | 评论(0) | 转发(0) |
0

上一篇:Super Jumping! Jumping! Jumping!

下一篇:没有了

给主人留下些什么吧!~~