zoukankan      html  css  js  c++  java
  • codeforces_B. Forgery

    http://codeforces.com/contest/1059/problem/B

    题意:

    For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3square without its central cell if it is completely contained inside the grid, as shown below.


    xxx
    x.x
    xxx

    Determine whether is it possible to forge the signature on an empty n×mn×m grid.

    思路:

    模拟。在给定的签名中寻找特定的点,该点的所有相邻点均被涂色,找到该点,将另一张空白纸上的该点相邻的点涂色,最后比较两张图是否相同。

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define LL long long
    
    char a[1005][1005],b[1005][1005];
    
    bool legal(int x,int y)
    {
        for(int i=-1; i<=1; i++)
            for(int j=-1; j<=1; j++)
            {
                if(i==0&&j==0)
                    continue;
                if(a[x+i][y+j]=='.')
                    return 0;
            }
        return 1;
    }
    
    void draw(int x,int y)
    {
        for(int i=-1; i<=1; i++)
            for(int j=-1; j<=1; j++)
            {
                if(i==0&&j==0)
                    continue;
                b[x+i][y+j]='#';
            }
    }
    
    int n,m;
    bool compareAB()
    {
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                if(a[i][j]!=b[i][j])
                    return 0;
        return 1;
    }
    
    int main()
    {
    
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++)
                    b[i][j]='.';
            for(int i=0; i<n; i++)
                scanf("%s",a[i]);
            for(int i=1; i<n-1; i++)
                for(int j=1; j<m-1; j++)
                {
                    if(legal(i,j))
                        draw(i,j);
                }
            if(compareAB())
                printf("YES
    ");
            else
                printf("NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    EM
    te2
    te
    XLnet
    GPT
    40.Properties
    38.特殊操作流
    37.I/O流
    35.File
    day68日考
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/9747682.html
Copyright © 2011-2022 走看看