HDU5546 Ancient Go(深搜DFS)(2015CCPC)
2017-04-25 20:46
337 查看
题目:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2263 Accepted Submission(s): 703
Problem Description
Yu Zhou likes to play Go with Su Lu. From the historical research, we found that there are much difference on the rules between ancient go and modern go.
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.
Input
The first line of the input gives the number of test cases, T(1≤T≤100). T test
cases follow. Test cases are separated by an empty line. Each test case consist of 9 lines represent the game board. Each line consists of 9 characters. Each character represents a cell on the game board. ′.′ represents
an empty cell. ′x′ represents
a cell with black chess which owned by Yu Zhou. ′o′ represents
a cell with white chess which owned by Su Lu.
Output
For each test case, output one line containing Case #x: y, where x is
the test case number (starting from 1) and y is Can
kill in one move!!! if Yu Zhou has a move to kill at least one of Su Lu's components. Can not kill in one move!!! otherwise.
Sample Input
2
.......xo
.........
.........
..x......
.xox....x
.o.o...xo
..o......
.....xxxo
....xooo.
......ox.
.......o.
...o.....
..o.o....
...o.....
.........
.......o.
...x.....
........o
Sample Output
Case #1: Can kill in one move!!!
Case #2: Can not kill in one move!!!
Hint
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.
Source
The 2015 China Collegiate Programming Contest
Recommend
wange2014 | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
Statistic | Submit | Discuss | Note
思路:
简单地说一下题意,周瑜和鲁肃下围棋,周瑜用的是‘X’,鲁肃用的是‘O’,现在该周瑜走了,问的是周瑜能不能再这一步吃掉鲁肃的至少一枚棋子(完全包围),原来的想法是把所有的o点记录下来,然后搜他附近有几个x,但是最后一直WA,最后换了种方法,找点每一个'.',然后放置棋子,看能不能吃,每走一步把走过的o标记为#
直接看代码吧
代码:
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define N 200200
#define M 1000000
#define ll long long
using namespace std;
char map[15][15],mp[15][15];
int go[4][2]= {0,1,1,0,-1,0,0,-1};
int flag;
void dfs(int x,int y)
{
for(int i=0; i<4; i++)
{
int xx=x+go[i][0];
int yy=y+go[i][1];
if(xx>=0&&xx<9&&yy>=0&&yy<9&&mp[xx][yy]=='.')
flag=1;
if(xx>=0&&xx<9&&yy>=0&&yy<9&&mp[xx][yy]=='o')
{
mp[xx][yy]='#';
dfs(xx,yy);
}
}
}
int jc()
{
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
{
if(mp[i][j]=='o')
{
mp[i][j]='#';
flag=0;
dfs(i,j);
if(flag==0)return 1;
}
}
}
return 0;
}
int main()
{
int t,q=1;
scanf("%d",&t);
while(t--)
{
int folg=0;
for(int i=0; i<9; i++)
scanf("%s",map[i]);
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
{
if(map[i][j]=='.')
{
map[i][j]='x';
memcpy(mp,map,sizeof(map));
if(jc())folg=1;
map[i][j]='.';
}
}
}
if(folg)
printf("Case #%d: Can kill in one move!!!\n",q++);
else
printf("Case #%d: Can not kill in one move!!!\n",q++);
}
return 0;
}
Ancient Go
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2263 Accepted Submission(s): 703
Problem Description
Yu Zhou likes to play Go with Su Lu. From the historical research, we found that there are much difference on the rules between ancient go and modern go.
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.
Input
The first line of the input gives the number of test cases, T(1≤T≤100). T test
cases follow. Test cases are separated by an empty line. Each test case consist of 9 lines represent the game board. Each line consists of 9 characters. Each character represents a cell on the game board. ′.′ represents
an empty cell. ′x′ represents
a cell with black chess which owned by Yu Zhou. ′o′ represents
a cell with white chess which owned by Su Lu.
Output
For each test case, output one line containing Case #x: y, where x is
the test case number (starting from 1) and y is Can
kill in one move!!! if Yu Zhou has a move to kill at least one of Su Lu's components. Can not kill in one move!!! otherwise.
Sample Input
2
.......xo
.........
.........
..x......
.xox....x
.o.o...xo
..o......
.....xxxo
....xooo.
......ox.
.......o.
...o.....
..o.o....
...o.....
.........
.......o.
...x.....
........o
Sample Output
Case #1: Can kill in one move!!!
Case #2: Can not kill in one move!!!
Hint
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.
Source
The 2015 China Collegiate Programming Contest
Recommend
wange2014 | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
Statistic | Submit | Discuss | Note
思路:
简单地说一下题意,周瑜和鲁肃下围棋,周瑜用的是‘X’,鲁肃用的是‘O’,现在该周瑜走了,问的是周瑜能不能再这一步吃掉鲁肃的至少一枚棋子(完全包围),原来的想法是把所有的o点记录下来,然后搜他附近有几个x,但是最后一直WA,最后换了种方法,找点每一个'.',然后放置棋子,看能不能吃,每走一步把走过的o标记为#
直接看代码吧
代码:
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define N 200200
#define M 1000000
#define ll long long
using namespace std;
char map[15][15],mp[15][15];
int go[4][2]= {0,1,1,0,-1,0,0,-1};
int flag;
void dfs(int x,int y)
{
for(int i=0; i<4; i++)
{
int xx=x+go[i][0];
int yy=y+go[i][1];
if(xx>=0&&xx<9&&yy>=0&&yy<9&&mp[xx][yy]=='.')
flag=1;
if(xx>=0&&xx<9&&yy>=0&&yy<9&&mp[xx][yy]=='o')
{
mp[xx][yy]='#';
dfs(xx,yy);
}
}
}
int jc()
{
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
{
if(mp[i][j]=='o')
{
mp[i][j]='#';
flag=0;
dfs(i,j);
if(flag==0)return 1;
}
}
}
return 0;
}
int main()
{
int t,q=1;
scanf("%d",&t);
while(t--)
{
int folg=0;
for(int i=0; i<9; i++)
scanf("%s",map[i]);
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
{
if(map[i][j]=='.')
{
map[i][j]='x';
memcpy(mp,map,sizeof(map));
if(jc())folg=1;
map[i][j]='.';
}
}
}
if(folg)
printf("Case #%d: Can kill in one move!!!\n",q++);
else
printf("Case #%d: Can not kill in one move!!!\n",q++);
}
return 0;
}
相关文章推荐
- 【HDU5546 2015 CCPC 南阳国赛G】【DFS】Ancient Go 棋盘围杀 优化写法O(n^2)
- 2015ccpc G - Ancient Go(围棋dfs爆搜)
- Ancient Go---hdu5546(dfs爆搜CCPC题目)
- 2015 南阳理工CCPC Ancient Go
- 2015 CCPC Ancient Go
- HDU 5546 Ancient Go (ccpc2015南阳G)
- Ancient Go【ccpc dfs】
- hdu5546 Ancient Go DFS搜索 国庆咸鱼
- 2015 南阳 CCPC hdu 5546 Ancient Go(DFS,暴力)
- hdu 5546 Ancient Go(2016ccpc) 暴力DFS
- 2015 南阳 CCPC G.Ancient Go
- HDU5546 Ancient Go(DFS)
- hdu5546 Ancient Go 简单深搜
- HDOJ 5546 Ancient Go(qwb铜牌题 DFS搜索)
- hdu 5546 Ancient Go(dfs)
- HDU 5546 Ancient Go——dfs
- dfs ancient go
- hdu 5546 Ancient Go 枚举 DFS
- hdu 5546 Ancient Go(dfs)
- HDU 5546 Ancient Go (dfs)