POJ 3314 Plaque Pack (模拟)

18 篇文章 0 订阅
Plaque Pack
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 988 Accepted: 468

Description

The Knick Knack Plaque Shack designs plaques of unusual shapes. All the plaques are 1 inch deep, and have a wide variety of shapes, some of which are shown below.

Ben Fitt is one of several workers in the shipping department (part of the Knick Knack Plaque Shack Pack, as they like to call themselves). Each day he is assigned the task of shipping all the plaques of a certain width to the various department stores which sell them. He has at his disposal boxes with a depth of 1 and a width equal to the plaques' width. As the plaques come off the assembly line, he fits them into the boxes one at a time. When placed in a box, each plaque will slide down until some part of it touches the topmost plaque already in the box (or the bottom of the box if it is the first plaque). For example, if the leftmost plaque above came off the assembly line first, followed by the middle and then the rightmost, they would stack up one on top of the other as shown on the left. If they came off the assembly line in reverse order, they would stack up as shown on the right.

When a plaque comes off the assembly line which will not fit into the box (i.e., it sticks up over the top), Ben closes that box, ships it off, and starts a new box. In the above examples, the height of the boxes is only 12, so it would take two boxes for the first ordering of plaques, but only one for the second. During his free moments between packing plaques, Ben wonders what it would be like if hundreds of computer programmers tried to write code to simulate this monotonous drudgery.

Input

Input will consist of multiple test cases. Each test case will start with a line containing three integersn w b, where n indicates the number of plaques to ship, w indicates the width of each plaque, andb indicates the height of each shipping box. These values will lie in the ranges 1 ... 100, 1 ... 10 and 1 ... 100, respectively. Following this line will ben specifications of plaque shapes. Each shape specification starts with a single line containing the integer heighth of the plaque (1 ≤ h ≤ 10 and h ≤ b). Following this will be h lines containingw characters each, where each character is either 'X' (indicating a part of the plaque ) or '.', indicating empty space. The order in which the plaques appear in the input is the order in which they must be packed in the boxes, and rotating or inverting the plaques is not allowed. The input file will end with the line 0 0 0.

Output

For each test case, output a single line containing the maximum height of the plaques in each box, in the order in which they are filled.

Sample Input

3 5 12
5
XXXXX
.XXXX
..XXX
...XX
....X
4
XXX..
..X..
..XXX
..X..
6
X....
X....
X....
X....
X....
XXXXX
3 5 12
6
X....
X....
X....
X....
X....
XXXXX
4
XXX..
..X..
..XXX
..X..
5
XXXXX
.XXXX
..XXX
...XX
....X
0 0 0

Sample Output

9 6
10

Source

East Central North America 2006

大体题意:
就是一个简单版的俄罗斯方块!
给你一个箱子高度为b,你有n 个俄罗斯方块,往这个箱子里填方块,每个方块高度小于等于b,且每个箱子里方块高度不得高于箱子,求出每个箱子的最大高度?
思路:
题目要求是按顺序放方块的,所有直接模拟这个过程就行了,然后比赛过程中没有做出来,思路有点不对!
赛后补了补,换了种思路!
建立一个结构体,表示这个方块,其实这个俄罗斯方块长什么样子是无所谓的,就是能不能往下怼= =!
所以我们我可以只记录方块每一列  下面数第一个X down[i],和从上面数第一个X up[i],如果可以往下怼的话,那么每一列都必须要求 up - down >= 1否则怼下一个= =!

其实这种模拟题没什么难得,关键就是细心点, 自己在多造几个样例肯定没问题了!
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100 + 10;
struct XBOX{
    int n;
    char s[maxn][maxn];
    int down[maxn];
    int up[maxn];
    int downhei;
}p[maxn];
vector<int >ans;
int main(){
    int n,w,b;
    while(scanf("%d %d %d",&n,&w,&b) == 3 && (n || w || b)){
        ans.clear();
        for (int i = 0; i < n; ++i){
            int h;
            scanf("%d",&h);
            for (int j = 0; j < h; ++j)scanf("%s",p[i].s[j]);
            p[i].n = h;
            for (int j = 0; j < w; ++j){
                for (int k = 0; k < h; ++k){
                    if (p[i].s[k][j] == 'X'){
                        p[i].up[j] = h-k-1;
                        break;
                    }
                }
            }
            for (int j = 0; j < w; ++j){
                for (int k = h-1; k >= 0; --k){
                    if (p[i].s[k][j] == 'X'){
                        p[i].down[j] = h-k-1;
                        break;
                    }
                }
            }
        }
        int cur = p[0].n;
        p[0].downhei = 0;
        for (int i = 1; i < n; ++i){
            p[i].downhei = cur;
            while(1){
                bool ok = true;
                for (int j = 0; j < w; ++j){
                    if (p[i].down[j] + p[i].downhei - p[i-1].up[j] - p[i-1].downhei <=  1){
                        ok =false;
                        break;
                    }

                }
                if (!ok)break;
                p[i].downhei--;
            }
            cur += p[i].n;
        }
//        for (int i =0 ; i < n;++i)printf("downhei = %d\n",p[i].downhei);
//        for (int i = 0; i < n; ++i){
//            for (int j = 0; j < w; ++j){
//                printf("%d ",p[i].down[j]);
//            }
//            puts("");
//        }
        int CurMax = 0;
        int subcur = 0;
        for (int i = 0; i < n; ++i){
            if (p[i].downhei - subcur + p[i].n > CurMax){
                if (p[i].downhei - subcur + p[i].n > b){
//                    printf("npew is %d\n",i);
                    ans.push_back(CurMax);
                    CurMax=p[i].n;
                    subcur = p[i].downhei;
                } else CurMax = p[i].downhei - subcur + p[i].n;
            }
        }
        if (CurMax <= b)ans.push_back(CurMax);
        int len = ans.size();
//        printf("len = %d\n",len);
        for (int i = 0; i < len ;++i){
            if (i)printf(" ");
            printf("%d",ans[i]);
        }
        puts("");
    }
    return 0;
}
/*
2 3 3
2
XXX
.X.
2
X.X
XXX
*/

/*
4 4 3
3
X..X
XXXX
XXXX
2
XXXX
.XX.
4
...X
...X
XXXX
XXXX
3
XXXX
XXX.
XXX.
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值