• POJ 2392 Space Elevator


    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 11172   Accepted: 5317

    Description

    The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) different types of blocks with which to build the tower. Each block of type i has height h_i (1 <= h_i <= 100) and is available in quantity c_i (1 <= c_i <= 10). Due to possible damage caused by cosmic rays, no part of a block of type i can exceed a maximum altitude a_i (1 <= a_i <= 40000). 

    Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.

    Input

    * Line 1: A single integer, K 

    * Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.

    Output

    * Line 1: A single integer H, the maximum height of a tower that can be built

    Sample Input

    3
    7 40 3
    5 23 8
    2 52 6

    Sample Output

    48

    Hint

    OUTPUT DETAILS: 

    From the bottom: 3 blocks of type 2, below 3 of type 1, below 6 of type 3. Stacking 4 blocks of type 2 and 3 of type 1 is not legal, since the top of the last type 1 block would exceed height 40.

    Source

    题目大意:n 种 石头 有每块石头的高度 每块石头的能所处的最大高度  以及每块石头的块数

    求 能到的最大高度

    思路: 按照 每种石头能所 处 得最大高度从小到大排序 (有贪心的思想)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int n;
    struct node{
        int h;
        int a;
        int c;
        bool operator < (const node &xxx)const 
        {
            return a<xxx.a;
        }
    }e[600]; 
    int f[400000],num[400000];
    int main()
    {
        cin>>n;
        for(int i=0;i<n;i++)
         cin>>e[i].h>>e[i].a>>e[i].c;
        sort(e,e+n);
        memset(f,0,sizeof f );
        f[0]=1;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            memset(num,0,sizeof num );
            for(int j=e[i].h;j<=e[i].a;j++)
            {
                if(!f[j]&&f[j-e[i].h]&&num[j-e[i].h]<e[i].c)// !f[j]  表示f[j] 没遍历 到过 即 非最优解
                {   //  f[j-e[i].h]为真 所以保证 f[j]能走到
                    f[j]=1;  
                    num[j]=num[j-e[i].h]+1;//统计该石块放置的个数  
                    if(ans<j)  
                      ans=j;
                }
            }
        }
        
        
        printf("%d",ans);
        return 0;
    }
  • 相关阅读:
    段间跳转之陷阱门
    段间跳转之中断门
    段间跳转之调用门
    代码段段间跳转流程
    Window内核学习之保护模式基础
    回顾2020,展望2021
    内存管理之堆
    Windows进程间通讯(IPC)----信号量
    线程本地存储(动态TLS和静态TLS)
    Windows进程间通讯(IPC)----套接字
  • 原文地址:https://www.cnblogs.com/suishiguang/p/5954089.html
Copyright © 2020-2023  润新知