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;
}
题目链接: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 389B:Fox and Cross
- Codeforces_389B_Fox and Cross(贪心)
- 模拟-codeforces-389B-Fox and Cross
- cf228 div2 B. Fox and Cross ( 贪心, 模拟)
- 【贪心+简单题】-CF-388A-A fox and box accumulation
- codeforces 389b Fox and Cross
- CF 510A(Fox And Snake-模拟)
- 贪心-codeforces-388A-Fox and Box Accumulation
- Codeforces Round #228 (Div. 2)B. Fox and Cross
- CF 510B(Fox And Two Dots-图上找环)
- CF D. Fox And Jumping
- CF 510C(Fox And Names-拓扑排序)
- Codeforces_388C_Fox and Card Game(博弈、贪心、排序)
- CF:322D - Ciel and Duel 贪心 或者 DP 我用的贪心 。。难道sort跟qsort是不一样的么?
- 【CF】D. Arthur and Walls(BFS + 贪心)
- CF B. Fox And Two Dots
- cf 342B - Xenia and Spies(贪心)
- CF 510E(Fox And Dinner-把质数拆成奇数和偶数)
- Codeforces Fox and Card Game (贪心,排序)
- codeforces389 E. Fox and Card Game【博弈 + 贪心】