您的位置:首页 > 其它

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

2014-02-06 15:30 429 查看
题意:给出一个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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: