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 Submission(s): 577 Accepted Submission(s): 213
Here is the rules for ancient go they were playing:
⋅The game is played on a 8×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×9 different positions to put the chess.
⋅Yu Zhou always takes the black and Su Lu the white. They put the chess onto the game board alternately.
⋅The chess of the same color makes connected components(connected by the board lines), for each of the components, if it's not connected with any of the empty cells, this component dies and will be removed from the game board.
⋅When one of the player makes his move, check the opponent's components first. After removing the dead opponent's components, check with the player's components and remove the dead components.
One day, Yu Zhou was playing ancient go with Su Lu at home. It's Yu Zhou's move now. But they had to go for an emergency military action. Little Qiao looked at the game board and would like to know whether Yu Zhou has a move to kill at least one of Su Lu's chess.
.......xo
.........
.........
..x......
.xox....x
.o.o...xo
..o......
.....xxxo
....xooo.
......ox.
.......o.
...o.....
..o.o....
...o.....
.........
.......o.
...x.....
........o
Case #2: Can not kill in one move!!!
In the first test case, Yu Zhou has 4 different ways to kill Su Lu's component.
In the second test case, there is no way to kill Su Lu's component.
#include <iostream>
#include <cstdio>
using namespace std; const int n = ;
const int dx[] = {-, , , }, dy[] = {, -, , };
int map[n][n];
int visit[n][n], flagcnt; inline bool Check(int x, int y)
{
if(x < || x >= n || y < || y >= n) return ;
return ;
} inline bool Search(int x, int y)
{
if(map[x][y] == ) return ;
if(map[x][y] == ) return ;
visit[x][y] = flagcnt;
for(int k = ; k < ; k++)
{
int tx = x + dx[k], ty = y + dy[k];
if(Check(tx, ty) && visit[tx][ty] != flagcnt)
{
if(Search(tx, ty))
return ;
}
}
return ;
} inline void Solve()
{
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
{
char ch = ' ';
while(ch != '.' && ch != 'x' && ch != 'o') ch = getchar();
if(ch == '.') map[i][j] = ;
else if(ch == 'o') map[i][j] = ;
else if(ch == 'x') map[i][j] = ;
} for(int i = ; i< ; i++)
for(int j = ; j < ; j++)
if(map[i][j] == )
{
map[i][j] = ;
for(int k = ; k < ; k++)
{
int x = i + dx[k], y = j + dy[k];
if(Check(x, y) && map[x][y] == )
{
++flagcnt;
if(!Search(x, y))
{
printf("Can kill in one move!!!\n");
return;
}
}
}
map[i][j] = ;
}
printf("Can not kill in one move!!!\n");
} int main()
{
int test;
scanf("%d", &test);
for(int testnumber = ; testnumber <= test; testnumber++)
{
printf("Case #%d: ", testnumber);
Solve();
}
return ;
}
The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546的更多相关文章
- The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550
Game Rooms Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- The 2015 China Collegiate Programming Contest Game Rooms
Game Rooms Time Limit: 4000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551
Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】
G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...
- The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547
Sudoku Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- The 2015 China Collegiate Programming Contest E. Ba Gua Zhen hdu 5544
Ba Gua Zhen Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
随机推荐
- Linear regression with one variable算法实例讲解(绘制图像,cost_Function ,Gradient Desent, 拟合曲线, 轮廓图绘制)_矩阵操作
%测试数据 'ex1data1.txt', 第一列为 population of City in 10,000s, 第二列为 Profit in $10,000s 1 6.1101,17.592 5. ...
- 大数计算_BigNum优化_加减乘除乘方取余_带注释_数组
#include <iostream> #include <algorithm> #include <cstring> #include <cstdlib&g ...
- springmvc中RedirectAttributes的作用
RedirectAttributes在重定向的时候可以传参,不能跨站传参,因为参数是保存在服务器端
- java.util.ConcurrentModificationException
遍历 List 的时候将 item remove 掉会抛出此异常
- NYOJ题目124中位数
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAJUCAIAAABsWvwaAAAgAElEQVR4nO3dPXLjuraG4TsJ5xqIYw
- MVC – 4.mvc初体验(1)
1.MVC请求模式 2.MVC简单请求流程图 展开 折叠 3.返回string的mvc方法 展开 折叠 4.加载视图的方法
- 设计模式学习之组合模式(Composite,结构型模式)(10)
转载地址:http://www.cnblogs.com/zhili/p/CompositePattern.html 一.引言 在软件开发过程中,我们经常会遇到处理简单对象和复合对象的情况,例如对操作系 ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
- Could not link against boost_system 解决办法
Could not link against boost_system 解决办法: 先安装 libboost-all-dev ./configure --with-incompatible-bdb - ...
- RSA 加解密算法
与DES不同,RSA算法中,每个通信主体都有两个钥匙,一个公钥一个私钥. 就是有2把钥匙1.使用publicKey可以对数据进行加密2.使用Key才能对数据进行解密单方向传输用公钥加密的数据,只有私钥 ...