• hdoj 1069


    Monkey and Banana

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 18640    Accepted Submission(s): 9918


    Problem Description
    A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

    The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. 

    They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked. 

    Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
     
    Input
    The input file will contain one or more test cases. The first line of each test case contains an integer n,
    representing the number of different blocks in the following data set. The maximum value for n is 30.
    Each of the next n lines contains three integers representing the values xi, yi and zi.
    Input is terminated by a value of zero (0) for n.
     
    Output
    For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height".
     
    Sample Input
    1
    10 20 30
    2
    6 8 10
    5 5 5
    7
    1 1 1
    2 2 2
    3 3 3
    4 4 4
    5 5 5
    6 6 6
    7 7 7
    5
    31 41 59
    26 53 58
    97 93 23
    84 62 64
    33 83 27
     
    Sample Output
    Case 1: maximum height = 40
    Case 2: maximum height = 21
    Case 3: maximum height = 28
    Case 4: maximum height = 342

    题意:要求堆方块,底下的长宽都要比上面的长宽大。求最高能堆多高。
     
    开始一看到这题目完全没有感觉啊!有木有?? 尽是往贪心上面有想法,看来暴力的题目做多了qwq。
    但是,dp的思路都是先有暴力的想法,才会有思路,所以一开始就往暴力上面想,都是一些奇奇怪怪的想法。但是,有关贪心,就想到排序。本菜鸡的思路就到此为止了qwq,(丢人)。
     
    然后去偷偷地看一下大佬的题解,直接是把长宽高的6种排列全部弄出来,然后,慢慢地遍历。(哇塞!!这这这,真的好暴力啊啊啊!!!)
     
     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 const int maxn=206;
     5 struct Point{
     6     int x,y,z;
     7 }good[maxn];
     8 
     9 bool cmp(Point a, Point b)
    10 {
    11     if( a.x==b.x) return a.y>b.y;
    12     return a.x>b.x;
    13 }
    14 
    15 int my_max(int x, int y)
    16 {
    17     return x>y?x:y;
    18 }
    19 
    20 int main()
    21 {
    22     int n,nn=1;
    23     while( ~scanf("%d",&n)&&n){
    24 
    25         int len=0;
    26         for(int i=1;i<=n;i++){
    27             int a[3];
    28             scanf("%d%d%d",&a[0],&a[1],&a[2]);
    29             for(int j=0;j<3;j++){
    30                 int x,y,z;
    31                 x=a[j]; y=a[(j+1)%3]; z=a[(j+2)%3];
    32                 good[++len].x=x; good[len].y=y; good[len].z=z;
    33                 good[++len].x=x; good[len].y=z; good[len].z=y;
    34             }
    35         }
    36         sort( good+1, good+1+len, cmp);
    37         good[0].x=good[0].y=1e7;
    38         good[0].z=0;
    39 
    40         int ans;
    41         for(int i=1;i<=len;i++){
    42             ans=0;
    43             for(int j=0;j<i;j++){
    44                 if( good[j].x>good[i].x&&good[j].y>good[i].y){
    45                     ans=my_max( ans, good[i].z+good[j].z);
    46                 }
    47             }
    48             good[i].z=ans;
    49         }
    50 
    51         ans=0;
    52         for(int i=1;i<=len;i++){
    53             ans=my_max( ans, good[i].z);
    54         }
    55 
    56         printf("Case %d: maximum height = %d
    ",nn++,ans);
    57     }
    58     return 0;
    59 }

    参考:https://www.cnblogs.com/forgot93/p/3496078.html

  • 相关阅读:
    flutter_bloc使用解析骚年,你还在手搭bloc吗!
    白嫖JetBrains正版全家桶!
    一文总结设计模式
    201671010119 201620172《Java程序设计》第五周学习心得
    201671010119 201620172《Java程序设计》第二周学习心得
    201671010119 201620172《Java程序设计》第三周学习心得
    201671010119 201620172《Java程序设计》第八周学习心得
    201671010119 201620172《Java程序设计》第四周学习心得
    201671010119 201620172《Java程序设计》第六周学习心得
    201671010119 201620172《Java程序设计》第一周学习心得
  • 原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9079369.html
Copyright © 2020-2023  润新知