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

题意:给出一个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;
}


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

上一篇:MySQL 设置允许远程登录


下一篇:Leveldb源码解析之Bloom Filter