zoukankan      html  css  js  c++  java
  • 【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
    ";
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++)
                cout<<b[i][j]<<" ";
            cout<<'
    ';
        }
        return 0;
    }
    
    
  • 相关阅读:
    hdu 2196 树形dp
    codeforces 1A
    [日常摸鱼]bzoj1218[HNOI2003]激光炸弹-二维前缀
    [日常摸鱼]bzoj2724蒲公英-分块
    [日常摸鱼]关于离散化
    [OI笔记]后缀自动机
    [日常摸鱼]poj1509Glass Beads-SAM
    [日常摸鱼]bzoj1083[SCOI2005]繁忙的都市-最小生成树
    [日常摸鱼]bzoj2038[2009国家集训队]小Z的袜子-莫队算法
    [日常摸鱼]三分法
  • 原文地址:https://www.cnblogs.com/gwj1314/p/12300282.html
Copyright © 2011-2022 走看看