Tetrooj Box

这是一个关于二维盒子堆积的问题,目标是确定所需的最大高度。输入包含基底长度和要放置的矩形块数量,每个块有水平长度、垂直长度和起始列位置。块会向下堆积直到碰到基底或其他块。输出是最高的列的高度。给出的示例展示了输入输出格式和解决此类问题的C++代码示例。

Tetrooj Box

时间限制:C/C++ 5秒,其他语言10秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述 

Dr. Orooji’s children have played Tetris but are not willing to help Dr. O with a related problem.
Dr. O’s children don’t realize that Dr. O is lucky to have access to 100+ great problem solvers and

great programmers today!

Dr. O knows the length of the base for a 2D box and wants to figure out the needed height for the
box. Dr. O will drop some 2D blocks (rectangles) on the base. A block will go down until it lands
on the base or is stopped by an already-dropped block (i.e., it lands on that block). After all the
blocks have been dropped, we can determine the needed height for the box – the tallest column is
the needed height (please see pictures on the next page corresponding to Sample Input/Output). 
 

输入描述:

The first input line contains two integers:b(1 ≤b≤ 100), indicating the length of the base andr
(1 ≤r≤50), indicating the number of blocks (rectangular pieces) to be dropped. Each of the next
rinput lines contains three integers: a block’shorizontal lengthh(1 ≤h≤100), the block’svertical
lengthv(1 ≤v≤100), andc(c≥1), the leftmost column the block is dropped into. Assume that
thehandcvalues will be such that the block will not go beyond the box base, i.e., (c+h–1)≤b.

输出描述:

Print the needed height for the box (the tallest column is the height).

示例1

输入

复制

10 4
2 3 1
4 2 2
1 7 6
1 3 4

输出

复制

8

说明

示例2

输入

复制

10 3
3 4 8
8 2 1
1 1 3

输出

复制

7

说明

#include<iostream>
#include<set>
#include<cstring>

using namespace std;
int main(){
    int d,n;
    cin>>d>>n;
    int a[110][11000];
    memset(a, 0, sizeof(a));
    int c,k,cc;
    int max=0;
    for(int i=0;i<n;i++){
        cin>>c>>k>>cc;
        int maxh=1;
        for(int j=cc+1;j<cc+c;j++){
            for(int h=0;h<110;h++){
                if(a[j][h]==1&&h>maxh)
                    maxh=h;
            }
        }
        for(int j=cc;j<=cc+c;j++){
            for(int h=maxh;h<=maxh+k;h++){
                a[j][h]=1;
            }
        }
    }
    for(int i=0;i<110;i++){
        for(int j=0;j<110;j++){
            if(a[i][j]==1&&j>max){
                max=j;
            }
        }
    }
    cout<<max;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值