Sicily 1407. Plaque Pack

来源:互联网 发布:大宝防晒霜如何 知乎 编辑:程序博客网 时间:2024/05/01 22:20

1407. Plaque Pack

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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 integers n w b, where n indicates the number of plaques to ship, w indicates the width of each plaque, and b 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 be nspecifications of plaque shapes. Each shape specification starts with a single line containing the integer height h of the plaque (1 ≤ h ≤ 10 and h ≤ b). Following this will be h lines containing w 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 125XXXXX.XXXX..XXX...XX....X4XXX....X....XXX..X..6X....X....X....X....X....XXXXX3 5 126X....X....X....X....X....XXXXX4XXX....X....XXX..X..5XXXXX.XXXX..XXX...XX....X0 0 0

Sample Output

9 610
很凶残的模拟题:
#include <stdio.h>char BOX[1005][15];//用来模拟箱子的数组int prev_h;int w, h_each_b;int each_box[100];//用来放每个箱子最大高度的数组int box_num;//装了的箱子个数bool can_move_down(int h_of_below_p[]) {//判断是否可以往下移动    for (int i = 0; i < w; i++) {        if (h_of_below_p[i] == 0 || BOX[h_of_below_p[i] - 1][i] == 'X')//最底了不能移动,下界之下有东西也不能移动            return false;    }    return true;}void move(int h_of_below_p[]) {//移动函数    int temp_h;    for (int i = 0; i < w; i++) {        for (temp_h = h_of_below_p[i]; BOX[temp_h][i] == 'X'; temp_h++) {//注意这里是列移动的,行移动很难写,要考虑是否会盖住下面已经存在的东西            BOX[temp_h - 1][i] = BOX[temp_h][i];        }        BOX[temp_h - 1][i] = '.';//上界的处理    }}bool all_point(int now_h) {//判断是否都是点,也即判断这一层是否是空的    for (int i = 0; i < w; i++) {        if (BOX[now_h - 1][i] == 'X')            return false;    }    return true;}void fill_in_BOX(int h_each_p) {    int k = prev_h - 1 + h_each_p;    for (int i = 0; i < h_each_p; i++) {//读入新的        scanf("%s", BOX[k]);        k--;    }        int h_of_below_p[10];//存放新的东西下界的i坐标(高度)    for (int i = 0; i < w; i++) {        h_of_below_p[i] = prev_h;//将下界定为最小的prev_h    }    for (int i = 0; i < w; i++) {//然后往上定位下界        while (BOX[h_of_below_p[i]][i] == '.')            h_of_below_p[i]++;    }        while (can_move_down(h_of_below_p)) {//只要能往下移动        move(h_of_below_p);        for (int i = 0; i < w; i++) {            h_of_below_p[i]--;//下界也要更新        }    }        int now_h = prev_h + h_each_p;//现在的高度,先定为最大值    while (all_point(now_h))//然后向下减小        now_h--;        if (now_h > h_each_b) {//如果现在高度爆了箱子        each_box[box_num++] = prev_h;//增加新箱子且存入上一个箱子的最大高度,就是先前的高度prev_h        for (int i = 0; i < w; i++) {//将新加入东西的下面都变成空,相当于新拿了一个箱子            for (int j = h_of_below_p[i] - 1; j >= 0; j--) {                BOX[j][i] = '.';            }        }                while (can_move_down(h_of_below_p)) {//然后将新东西往下移动            move(h_of_below_p);            for (int i = 0; i < w; i++) {                h_of_below_p[i]--;            }        }        prev_h = h_each_p;//那么高度就应该更新为这个新东西的高度    } else if (now_h < h_each_b) {        prev_h = now_h;//如果高度没爆箱子,就更新高度    } else {        for (int i = 0; i < w; i++) {//如果刚好等于,清空当前箱子            for (int j = 0; j <= h_each_b; j++) {                BOX[j][i] = '.';            }        }        each_box[box_num++] = now_h;//上一个箱子装满了        prev_h = 0;//下一个新箱子的高度由于没有东西就是0了    }}bool BOX_is_empty() {    for (int i = 0; i < w; i++) {//判断最底层是否为空就知道箱子是否为空        if (BOX[0][i] == 'X')            return false;    }    return true;}int main() {    int n;    while (scanf("%d%d%d", &n, &w, &h_each_b) && n && w && h_each_b) {        for (int i = 0; i < 1005; i++) {            for (int j = 0; j < w; j++) {                BOX[i][j] = '.';            }        }        int h_each_p;//每个东西的高度        prev_h = 0;//箱子中已经装的东西的高度        box_num = 0;        for (int i = 0; i < n; i++) {            scanf("%d", &h_each_p);            fill_in_BOX(h_each_p);//装箱        }        if (!BOX_is_empty())//判断箱子是否为空,假如不是,说明最后还有一个箱子要处理            each_box[box_num++] = prev_h;        for (int i = 0; i < box_num; i++) {//输出            if (i != 0)                printf(" ");            printf("%d", each_box[i]);        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击