【CF 551B】Serval and Toy Bricks

B. Serval and Toy Bricks
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.

He has a special interest to create difficult problems for others to solve. This time, with many 1×1×1 toy bricks, he builds up a 3-dimensional object. We can describe this object with a ?×? matrix, such that in each cell (?,?), there are ℎ?,? bricks standing on the top of each other.

However, Serval doesn’t give you any ℎ?,?, and just give you the front view, left view, and the top view of this object, and he is now asking you to restore the object. Note that in the front view, there are ? columns, and in the ?-th of them, the height is the maximum of ℎ1,?,ℎ2,?,…,ℎ?,?. It is similar for the left view, where there are ? columns. And in the top view, there is an ?×? matrix ??,?, where ??,? is 0 or 1. If ??,? equals 1, that means ℎ?,?>0, otherwise, ℎ?,?=0.

However, Serval is very lonely because others are bored about his unsolvable problems before, and refused to solve this one, although this time he promises there will be at least one object satisfying all the views. As his best friend, can you have a try?

Input
The first line contains three positive space-separated integers ?,?,ℎ (1≤?,?,ℎ≤100) — the length, width and height.

The second line contains ? non-negative space-separated integers ?1,?2,…,??, where ?? is the height in the ?-th column from left to right of the front view (0≤??≤ℎ).

The third line contains ? non-negative space-separated integers ?1,?2,…,?? (0≤??≤ℎ), where ?? is the height in the ?-th column from left to right of the left view.

Each of the following ? lines contains ? numbers, each is 0 or 1, representing the top view, where ?-th number of ?-th row is 1 if ℎ?,?>0, and 0 otherwise.

It is guaranteed that there is at least one structure satisfying the input.

Output
Output ? lines, each of them contains ? integers, the ?-th number in the ?-th line should be equal to the height in the corresponding position of the top view. If there are several objects satisfying the views, output any one of them.

Examples
inputCopy
3 7 3
2 3 0 0 2 0 1
2 1 3
1 0 0 0 1 0 0
0 0 0 0 0 0 1
1 1 0 0 0 0 0
outputCopy
1 0 0 0 2 0 0
0 0 0 0 0 0 1
2 3 0 0 0 0 0
inputCopy
4 5 5
3 5 2 0 4
4 2 5 4
0 0 0 0 1
1 0 1 0 0
0 1 0 0 0
1 1 1 0 0
outputCopy
0 0 0 0 4
1 0 2 0 0
0 5 0 0 0
3 4 1 0 0
Note

The graph above illustrates the object in the first example.

The first graph illustrates the object in the example output for the second example, and the second graph shows the three-view drawing of it.

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[110][110], b[110][110], x[110], y[110];
int main(){
    int n, m, h;
    cin>>n>>m>>h;
    for(int i = 1; i <= m; i++)cin>>y[i];
    for(int i = 1; i <= n; i++)cin>>x[i];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++)
            {cin>>a[i][j]; b[i][j] = a[i][j];}
    }
    for(int i = h; i >= 1; i--){
        for(int j = 1; j <= n; j++){
            int f = 0;
            if(x[j]>=i)f = 1;
            for(int k = 1; k <= m; k++){
                if(y[k]==i && f==1 && a[j][k]){
                    b[j][k] = i;
                }else if(y[k]>=i && x[j]==i && f==1 && a[j][k]){
                    b[j][k] = i;
                }
            }
        }
    }
    //cout<<"ans\n";
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++)
            cout<<b[i][j]<<" ";
        cout<<'\n';
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小哈里

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

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

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

打赏作者

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

抵扣说明:

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

余额充值