首页 > 其他 > 详细

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

时间:2014-02-06 17:11:08      阅读:314      评论:0      收藏:0      [点我收藏+]

题意:给出一个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(贪心)

原文:http://blog.csdn.net/scnu_jiechao/article/details/18949925

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!