题目链接:Codeforces 389B Fox and Cross
题目大意:给出一张n*n的图,问说是否能用十字架将所有‘#’的位置补全。
解题思路:纯dfs,水题。
#include <stdio.h>
#include <string.h>
const int N = 105;
const int d[5][2] = { {0, 0}, {1, -1}, {1, 0}, {1, 1}, {2, 0} };
int n, v[N][N];
char g[N][N];
bool insert(int x, int y) {
for (int i = 0; i < 5; i++) {
int p = x + d[i][0], q = y + d[i][1];
if (p < 0 || p >= n || q < 0 || q >= n) return false;
if (v[p][q] || g[p][q] != '#') return false;
}
return true;
}
void clear (int x, int y, int val) {
for (int i = 0; i < 5; i++)
v[x + d[i][0]][y + d[i][1]] = val;
}
bool dfs(int x, int y) {
if (y == n) {
y = 0; x++;
}
if (x == n) return true;
if (g[x][y] == '.' || v[x][y]) return dfs(x, y + 1);
if (!insert(x, y)) return false;
clear(x, y, 1);
bool flag = dfs(x, y + 1);
clear(x, y, 0);
return flag;
}
int main () {
memset(v, 0, sizeof(v));
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%s", g[i]);
printf("%s\n", dfs(0, 0) ? "YES" : "NO");
return 0;
}
分享到:
相关推荐
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
codeforces每日一题。 题意: 给出一个数组,让你挑选出能组成任意pair差值为2的幂的序列,并且使这个序列长度尽可能大。 思路: 针对于挑选出来的序列,任意pair对的差值为2的幂数。 假设有多个pair对,设dis(a,b)=2...
Codeforces round 678 D2_Codeforces_源码
打codeforces的神器
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
codeforces-js Codeforces JS
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
Codeforces Round #723 (Div. 2).md