CF - 389 - B. Fox and Cross(贪心)

来源:互联网 发布:ipad 软件 编辑:程序博客网 时间:2024/06/01 18:12

题意:给出一个n*n的图,问这个图是否能由十字架拼成(3 ≤ n ≤ 100)。

题目链接:http://codeforces.com/problemset/problem/389/B

——>>最上面一行的#,一定是一个十字架的头部,判断该头部是否符合要求即可。

#include <cstdio>using namespace std;const int maxn = 100 + 10;char G[maxn][maxn];int main(){    int n;    while(scanf("%d", &n) == 1) {        int sum = 0;        for(int i = 0; i < n; i++) {            getchar();            for(int j = 0; j < n; j++) {                G[i][j] = getchar();                if(G[i][j] == '#') sum++;            }        }        bool ok = true;        if(sum % 5) ok = false;        if(ok) {            for(int i = 0; i < n; i++) {                if(!ok) break;                for(int j = 0; j < n; j++)                    if(G[i][j] == '#') {                        if(!j || j == n-1 || i > n-3 || G[i+1][j] != '#' || G[i+1][j-1] != '#' || G[i+1][j+1] != '#' || G[i+2][j] != '#') {                            ok = false;                            break;                        }                        G[i+1][j] = G[i+1][j-1] = G[i+1][j+1] = G[i+2][j] = '.';                    }            }        }        ok ? puts("YES") : puts("NO");    }    return 0;}


0 0
原创粉丝点击