【CF 551B】Serval and Toy Bricks

举报
小哈里 发表于 2022/04/29 22:46:16 2022/04/29
【摘要】 B. Serval and Toy Bricks time limit per test1 second memory limit per test256 megabytes inputstandard ...

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;
}


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。

原文链接:gwj1314.blog.csdn.net/article/details/89290825

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。