CodeForces - 1059B - Forgery(模拟)

题目链接:https://vjudge.net/problem/CodeForces-1059B

题目大意:你有一个可以盖出一个3*3 ‘#’中心为‘.’的章,问你能不能盖出图中的形状

  其实简单模拟一下就行了.....如果盖下一个章,那么这个章的中心8个方向一定是'#',那我们反过来做一个'.'图,只要原图某个点的8个方向都是'#',那我们就以这个点为中心盖一个章,最后对比一下我们构造的图和原图,如果不一样,那肯定是无法盖出图中的形状的.

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e3+10;
char omap[maxn][maxn], vmap[maxn][maxn];
int dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
bool ok(int x, int y) {
    for (int i = 0; i<8; ++i) {
        int newx = x+dir[i][0], newy = y+dir[i][1];
        if (omap[newx][newy]=='.') return false;
    }
    return true;
}
void make(int x, int y) {
    for (int i = 0; i<8; ++i) {
        int newx = x+dir[i][0], newy = y+dir[i][1];
        vmap[newx][newy] = '#';
    }
}
bool checker(int n, int m) {
    for (int i = 0; i<n; ++i)
        for (int j = 0; j<m; ++j)
            if (omap[i][j]!=vmap[i][j]) return false;
    return true;
}
int main(void) {
    int n, m;
    while(~scanf("%d%d", &n, &m)) {
        for (int i = 0; i<n; ++i)
            scanf("%s", omap[i]);
        for (int i = 0; i<n; ++i) //全部初始化为.图
            for (int j = 0; j<m; ++j)
                vmap[i][j] = '.';
        for (int i = 1; i<n-1; ++i) 
            for (int j = 1; j<m-1; ++j) //参考样例2,中心不能在边缘
                if (ok(i, j)) make(i, j); //如果一个点8个方向都有#那么就以这个点为中心盖一个章
        printf(checker(n, m) ? "YES\n" : "NO\n"); //对比两个图是否一样
    }
    return 0;
}

 

posted @ 2020-03-03 12:31  shuitiangong  阅读(163)  评论(0编辑  收藏  举报