HDOJ 1069_大二写

Posted phalq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDOJ 1069_大二写相关的知识,希望对你有一定的参考价值。

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
", count, max_universe);
        count++;
    }
    
    
    fclose(stdin);
    system("pause");
    return 0;
}

 

以上是关于HDOJ 1069_大二写的主要内容,如果未能解决你的问题,请参考以下文章

HDOJ_1290_大二写_献给杭电五十周年校庆的礼物

HDOJ1069动态规划

hdoj 1069

hdoj_2546饭卡(强忍悲痛,好好写题解)

HDoj 2029 Palindromes _easy version

HDOJ_1003_MaxSum