zoukankan      html  css  js  c++  java
  • poj 4001 To Miss Our Children Time

                                                                               To Miss Our Children Time

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
    Total Submission(s): 4740    Accepted Submission(s): 1319


    Problem Description
    Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy, now he grows up. In the dead of night, he often misses something, including a simple game which brings him much happy when he was child. Here are the game rules: There lies many blocks on the ground, little LLL wants build "Skyscraper" using these blocks. There are three kinds of blocks signed by an integer d. We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is
    thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length and width which lies under the block. Here are some blocks. Can you know what's the highest "Skyscraper" can be build using these blocks?
     
    Input
    The input has many test cases.
    For each test case the first line is a integer n ( 0< n <= 1000) , the number of blocks.
    From the second to the n+1'th lines , each line describing the i‐1'th block's a,b,c,d (1 =< ai,bi,ci <= 10^8 , d = 0 or 1 or 2).
    The input end with n = 0.
     
    Output
    Output a line contains a integer describing the highest "Skyscraper"'s height using the n blocks.
     
    Sample Input
    3 10 10 12 0 10 10 12 1 10 10 11 2 2 10 10 11 1 10 10 11 1 0
     
    Sample Output
    24 11
     
    题意:堆长方体,一共三种类型的长方体,0型号的长方体必须堆在长和宽都小于等于本身的长方体之上,1型号的长方体必须堆在长或者宽小于等于它本身的长方体之上,也就是说在其下面的长方体必有长或宽中一者是小于该长方体的。2型号的长方体必须堆在长和宽都完全小于其本身的长方体之上。满足上述条件,求能堆多高。
    思路:先排好序,让长和宽数值比较大的长方体尽量先堆。这样排在队列前面的长方体肯定比排在后面的长方体先开始堆,递推,可以利用dp。
    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<cmath>
    #include<queue>
    #include<set>
    #include<map>
    using namespace std;
    typedef long long ll;
    const int N_MAX = 1000 + 5;
    ll dp[N_MAX];
    int n;
    struct Cube {
        ll w, l,h;
        int id;
        bool operator <(const Cube&b) {
            if (this->l != b.l)return this->l < b.l;
            else if(this->w!=b.w) return this->w < b.w;
            else return this->id > b.id;
        }
    }cube[N_MAX];
    
    bool judge(const Cube& a,const Cube& b) {//b要堆在a上面
        if (b.id == 0)return b.l >= a.l&&b.w >= a.w;
        if (b.id == 1)return (b.l >= a.l&&b.w > a.w) || (b.l > a.l&&b.w >= a.w);
        return b.l > a.l&&b.w > a.w;
    }
    
    void Dp() {
        for (int i = 0; i < n;i++) {
            dp[i] = cube[i].h;
        }
        for (int i = 1; i < n;i++) {//每次cube[i]要堆在最上面    
                for (int j = 0; j < i;j++) {
                    if (judge(cube[j], cube[i]))dp[i] = max(dp[i], dp[j] + cube[i].h);
                }
        }
        ll sum = *max_element(dp, dp + n);
        printf("%I64d
    ",sum);
    }
    
    int main() {
        while (scanf("%d",&n)&&n) {
            for (int i = 0; i < n;i++) {
                scanf("%I64d%I64d%I64d%d",&cube[i].l,&cube[i].w,&cube[i].h,&cube[i].id);
                if (cube[i].l < cube[i].w)swap(cube[i].l, cube[i].w);
          }
            sort(cube, cube + n);
            Dp();
        }
        return 0;
    }
     
  • 相关阅读:
    【css】如何实现响应式布局
    【PHP】foreach语法
    【css】cursor鼠标指针光标样式知识整理
    【JavaScript】修改图片src属性切换图片
    【PHP】PHP中的排序函数sort、asort、rsort、krsort、ksort区别分析
    【PHP】常用的PHP正则表达式收集整理
    【Mysql】mysql中bigint、int、mediumint、smallint 和 tinyint的取值范围
    js获取url参数的方法
    SQL Server 2008 geometry 数据类型
    SQL Server 存储过程之基础知识(转)
  • 原文地址:https://www.cnblogs.com/ZefengYao/p/7045885.html
Copyright © 2011-2022 走看看