[ACM Day5]L.Logic Puzzle

题目描述

看了半天才明白这道题到底要做什么事情,首先给你一个 (h+2)(w+2) ( h + 2 ) ∗ ( w + 2 ) maze m a z e ,需要你对其进行涂色,涂色后满足每个一个点(包括它自己在内)共九个格子中的黑色格子的数目等于它自身所带的权值,如果不能涂色则输出 impossible i m p o s s i b l e

数据范围

1<=h,w<=100 1 <= h , w <= 100

分析

在一个九宫格中考虑最左上角的点,如果当前到这个点的权值没有变成 0 0 <script type="math/tex" id="MathJax-Element-160">0</script>,则说明这个点不能被之前已经涂色的点满足条件,则这个点就是需要涂色的点。

#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
int _read(){
    char ch = getchar();
    int x = 0 , f = 1 ;
    while( !isdigit( ch ) )
           if( ch == '-' ) f = -1 , ch = getchar();
           else ch = getchar();
    while( isdigit( ch ) )
           x = (ch  - '0') + x * 10 , ch =  getchar();
    return x * f;
}
const int maxn = 400 + 5;
int c[maxn][maxn] , m[maxn][maxn];
int main(){
    int h = _read() , w = _read();
    rep( i , 1 , h + 2 )
        rep( j , 1 , w + 2 ) c[i][j] = _read();
    rep( i , 1 , h )
        rep( j , 1 , w )
            if( c[i][j] ){
                m[i][j] = 1;
                for( int k = i ; k <= i + 2 ; ++k )
                    for( int l = j ; l <= j + 2 ; ++l ) c[k][l]--;
            }
    rep( i , 1 , h + 2 )
        rep( j , 1 , w + 2 )
            if( c[i][j] ){
                puts("impossible");
                return 0;
            }
    rep( i , 1 , h ){
        rep( j , 1 , w ) printf("%c" , m[i][j] ? 'X' : '.');
        printf("\n");
    }       
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值