HDU 5546 Ancient Go (搜索)
题意:
- 棋盘有8×8个格子,棋子下在棋盘的交叉点上,故可以有9×9个落子的位置
- Alice执黑棋Bob执白棋轮流落子
- 与棋子直线相连的空白交叉点叫做气。当这些气都被对方棋子占据后,该棋子就没有了“气”,要被从棋盘上提掉。如果棋子的相邻(仅上下左右)直线交叉点上有了同色的棋子,则这两个棋子被叫做相连的。任意多个棋子可以以此方式联成一体,连成一体的棋子的气的数目是所有组成这块棋的单个棋子气数之和。如果这些气都被异色棋子占领,这块棋子就要被一起提掉。
- 当一方落子后,先检查对手的棋子,将没有“气”的对手的棋子从棋盘上提掉,再检查该方的棋子,将没有“气”的棋子提掉
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
char s[maxn][maxn];
bool vis[maxn][maxn]; bool dfs(int r, int c){
if(s[r][c] == '.') return false;
vis[r][c] = 1;
for(int i = 0; i < 4; ++i){
int x = r + dr[i];
int y = c + dc[i];
if(!is_in(x, y) || vis[x][y] || s[x][y] == 'x') continue;
if(!dfs(x, y)) return false;
}
return true;
} bool solve(){
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
if(s[i][j] == 'o'){
memset(vis, 0, sizeof vis);
if(dfs(i, j)) return true;
}
return false;
} int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
n = m = 9;
for(int i = 0; i < n; ++i) scanf("%s", s+i);
bool ok = false;
for(int i = 0; i < 9 && !ok; ++i)
for(int j = 0; j < 9 && !ok; ++j){
if(s[i][j] == '.'){
s[i][j] = 'x';
ok = solve();
s[i][j] = '.';
}
}
printf("Case #%d: %s\n", kase, ok ? "Can kill in one move!!!" : "Can not kill in one move!!!");
}
return 0;
}
HDU 5546 Ancient Go (搜索)的更多相关文章
- (hdu)5546 Ancient Go
Problem Description Yu Zhou likes to play Go with Su Lu. From the historical research, we found that ...
- The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546
Ancient Go Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- HDU 4616 Game (搜索)、(树形dp)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4616 这道题目数据可能比较弱,搜索都可以AC,但是不敢写,哎…… 搜索AC代码: #include & ...
- [HDU 2102] A计划(搜索题,典型dfs or bfs)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 4722(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 思路:简单的记忆化搜索,留意一下A==0时的情况就可以了. #include<iostre ...
- hdu 1010(迷宫搜索,奇偶剪枝)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- hdu 5335 Walk Out (搜索)
题目链接: hdu 5335 Walk Out 题目描述: 有一个n*m由0 or 1组成的矩形,探险家要从(1,1)走到(n, m),可以向上下左右四个方向走,但是探险家就是不走寻常路,他想让他所走 ...
- HDU 1896 Stones --优先队列+搜索
一直向前搜..做法有点像模拟.但是要用到出队入队,有点像搜索. 代码: #include <iostream> #include <cstdio> #include <c ...
- HDU 1978 记忆化搜索(dfs+dp)
Y - How many ways Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 【BZOJ4514】[Sdoi2016]数字配对 费用流
[BZOJ4514][Sdoi2016]数字配对 Description 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ...
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.
今天电脑死机了2次,重启电脑开eclipse后,发现项目环境坏了.百度后得到的答案是删除.metadata目录.但觉得麻烦,后在stackoverflow发现最佳的方式是 把 .metadata/.p ...
- Pentaho BIServer Community Edtion 6.1 使用教程 第二篇 迁移元数据 [HSQLDB TO MySQL]
第一部分 迁移原因 Pentaho BI 社区版服务的很多元数据信息存储在数据库汇总,其默认使用HSQLDB 数据库,即借助它存储自身的资料库,比如 Quartz 调度信息.业务资料库连接信息(数据 ...
- PopupWindow 实现 查看所有手机应用弹出框
public class MainActivity extends Activity implements OnItemLongClickListener, OnClickListener { pri ...
- Android 修改Menu字体颜色和背景
我们知道,在Android中修改TextView的字体颜色,一般是通过setTextColor()方法.虽说Android的Menu菜单项的每一项都是由TextView组成,但是Android的sdk ...
- 只会用就out了,手写一个符合规范的Promise
Promise是什么 所谓Promise,简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果.从语法上说,Promise 是一个对象,从它可以获取异步操作的消息.Prom ...
- 20145239 杜文超《Java程序设计》课程总结
<每周读书笔记链接汇总> 第一周读书笔记:http://www.cnblogs.com/dwc929210354/p/5247666.html 第二周读书笔记:http://www.cnb ...
- UVA12103 —— Leonardo's Notebook —— 置换分解
题目链接:https://vjudge.net/problem/UVA-12103 题意: 给出大写字母“ABCD……Z”的一个置换B,问是否存在一个置换A,使得A^2 = B. 题解: 对于置换,有 ...
- css3-rotate实现超炫环形旋转特效
css3-rotate实现超炫环形旋转特效,css3特效,环形旋转,圆形旋转,css3-rotate实现超炫环形旋转特效是一款采用css3 rotate实现的蓝色环形旋转特效代码. http://ww ...
- HDU 4652 Dice:期望dp(成环)【错位相减】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意: 给你一个有m个面的骰子. 两种询问: (1)"0 m n": “最后 ...