码迷,mamicode.com
首页 > 其他好文 > 详细

BNUOJ33568 Glass Pyramid(DFS)

时间:2015-04-19 22:51:49      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

Glass Pyramid

1000ms
65536KB
This problem will be judged on Ural. Original ID: 1968
64-bit integer IO format: %lld      Java class name: (Any)
Font Size:   
Type:   
技术分享
Vova is a skyscraper fan. When he arrives in a city that has any skyscrapers, he always tries to get to the observation deck in the highest skyscraper to make several shots from there. This time is no exception. As soon as Vova arrived in Hong Kong, right after checking in a hotel, he got to the International Commercial Center, a 118-floor building that was built a couple of years ago.
Before the main entrance into the International Commercial Center there is a pyramid of large glass blocks. Each block has the shape of a one meter height rectangular parallelepiped with a 2 × 2 meter square base. The pyramid‘s lowest layer is m × nmeter large. The second layer is (m ? 2) × (n ? 2) meter large and is located so that the vertices of each block‘s lower side coincided with the centers of the upper sides of the previous layer. The third and the next layers are constructed similarly. The upper layer consists of a single row of blocks (specifically, at m = n it consists of one block). Some pyramid blocks are made of colorless glass and the other blocks are made of reddish glass.
When Vova got to the observation platform, located at the skyscraper‘s 100-th floor, he saw the pyramid from there as a rectangular field, divided into 1 × 1 meter cells. The reddish hue of each cell hinted the number of reddish glass blocks that laid on this cell. Vova took the photo of the pyramid from above and now he wants you to take a look at this photo and find out which pyramid blocks are made of reddish glass and which ones are made of colorless glass. Vova also says that there is no reddish block lying exactly above a colorless block.

Input

The first line contains integers m and n that are sizes of the pyramid‘s base (2 ≤ m, n ≤ 40; m and n are even). Then m lines follow, each of them contains n non-negative integers, describing the photo Vova took. Each integer shows the number of reddish blocks lying above the corresponding cell. It is guaranteed that the input gives some possible arrangement of blocks in the pyramid.

Output

Print the description of the layers, from the lowest one to the highest one. To print information about the i-th layer, use ki lines each containing li characters (k1 = m/2; l1 =n/2; ki = ki ? 1 ? 1; li = li ? 1 ? 1). Character “R” represents a reddish block, “W” represents a colorless block. Each next layer is separated from the previous one by an empty line. If there are multiple solutions, you can print any of them.

Sample Input

input output
4 6
0 0 1 1 0 0
0 0 1 2 1 0
0 0 0 1 2 1
0 0 0 0 1 1
WRW
WWR

WR

Source

#include<stdio.h>
const int N = 50;

int mapt[N][N];

void print(int sx,int sy)
{
    int mint=1;
    for(int i=sx;i<sx+2;i++)
        for(int j=sy;j<sy+2;j++)
        if(mapt[i][j]<mint)
        mint=mapt[i][j];

    for(int i=sx;i<sx+2;i++)
        for(int j=sy;j<sy+2;j++)
        mapt[i][j]-=mint;
    printf("%s",mint>0?"R":"W");
}
int numb;
void dfs(int rs,int re,int hs,int he,int k)
{
    for(int i=rs;i<re;i+=2)
    {
        for(int j=hs;j<he;j+=2)
        {
            print(i,j);
        }
        printf("\n");
    }
    if(k>=numb)
        return ;
    printf("\n");
    dfs(rs+1,re-1,hs+1,he-1,k+1);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            scanf("%d",&mapt[i][j]);
        numb=n;
        if(numb>m)
            numb=m;
        numb-=2;
        dfs(1,n,1,m,1);
    }
}

BNUOJ33568 Glass Pyramid(DFS)

标签:

原文地址:http://blog.csdn.net/u010372095/article/details/45133337

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!