ZOJ - 1628 Diamond
2016-07-23 19:57
323 查看
Diamond
Status
Description
Diamond mine is a mini-game which is played on an 8 * 8 board as you can see below.
The board is filled with different colors of diamonds. The player can make one move at a time. A move is legal if it swaps two adjacent diamonds(not diagonally) and after that, there are three or more adjacent diamonds in a row or column with the same color.
Those diamonds will be taken away and new diamonds will be put in their positions. The game continues until no legal moves exist.
Given the board description. You are going to determine whether a move is legal.
Input
The input contains several cases. Each case has exactly 9 lines. The first 8 lines each contains a string of 8 characters. The characters are 'R'(Red), 'O'(Orange), 'G'(Green), 'P'(Purple), 'W'(White), 'Y'(Yellow) or 'B'(Blue). All characters are uppercase.
No 3 diamonds of the same color are initially in adjacent positions in a row or column. The last line has 4 integers in the form " row1 column1 row2 column2" describing the postions of the 2 diamonds that the player wants to swap. Rows are marked 1 to 8 increasingly
from top to bottom while columns from left to right. Input is terminated by EOF.
Output
For each case, output "Ok!" if the move is legal or "Illegal move!" if it is not.
Sample Input
PBPOWBGW
RRPRYWWP
YGBYYGPP
OWYGGRWB
GBBGBGGR
GBWPPORG
PPGORWOG
WYWGYWBY
4 3 3 3
PBPOWBGW
RRPRYWWP
YGBYYGPP
OWYGGRWB
GBBGBGGR
GBWPPORG
PPGORWOG
WYWGYWBY
5 5 6 5
Sample Output
Ok!
Illegal move!
这题看似简单其实特别坑输入的坐标还有可能不相邻和超过范围。。。真是无节操坑
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 20;
char str
;
int judge(int x,int y);
int main()
{
while(scanf("%s",str[0])!=EOF)
{
for(int i=1; i<8; i++)
{
scanf(" %s",str[i]);
}
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
int flag=0;
if((abs(x1-x2)+abs(y2-y1)!=1)||(x1<1)||(x1>8)||(x2<1)||(x2>8)||(y1<1)||(y1>8)||(y2<1)||(y2>8))//技巧
{
flag=0;
}
else
{
char tmp;
tmp=str[x1-1][y1-1],str[x1-1][y1-1]=str[x2-1][y2-1],str[x2-1][y2-1]=tmp;
for(int i=0; i<8; i++)
{
for(int j=0; j<8; j++)
{
if(judge(i,j))
{
flag=1;
break;
}
}
if(flag==1)
{
break;
}
}
}
if(flag==1)
{
printf("Ok!\n");
}
else
{
printf("Illegal move!\n");
}
memset(str,0,sizeof(str));
}
return 0;
}
int judge(int x,int y)
{
if(y<6&&str[x][y+1]==str[x][y+2]&&str[x][y+1]==str[x][y])
{
return 1;
}
if(x<6&&str[x+1][y]==str[x+2][y]&&str[x+1][y]==str[x][y])
{
return 1;
}
return 0;
}
Time Limit: 2MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Diamond mine is a mini-game which is played on an 8 * 8 board as you can see below.
The board is filled with different colors of diamonds. The player can make one move at a time. A move is legal if it swaps two adjacent diamonds(not diagonally) and after that, there are three or more adjacent diamonds in a row or column with the same color.
Those diamonds will be taken away and new diamonds will be put in their positions. The game continues until no legal moves exist.
Given the board description. You are going to determine whether a move is legal.
Input
The input contains several cases. Each case has exactly 9 lines. The first 8 lines each contains a string of 8 characters. The characters are 'R'(Red), 'O'(Orange), 'G'(Green), 'P'(Purple), 'W'(White), 'Y'(Yellow) or 'B'(Blue). All characters are uppercase.
No 3 diamonds of the same color are initially in adjacent positions in a row or column. The last line has 4 integers in the form " row1 column1 row2 column2" describing the postions of the 2 diamonds that the player wants to swap. Rows are marked 1 to 8 increasingly
from top to bottom while columns from left to right. Input is terminated by EOF.
Output
For each case, output "Ok!" if the move is legal or "Illegal move!" if it is not.
Sample Input
PBPOWBGW
RRPRYWWP
YGBYYGPP
OWYGGRWB
GBBGBGGR
GBWPPORG
PPGORWOG
WYWGYWBY
4 3 3 3
PBPOWBGW
RRPRYWWP
YGBYYGPP
OWYGGRWB
GBBGBGGR
GBWPPORG
PPGORWOG
WYWGYWBY
5 5 6 5
Sample Output
Ok!
Illegal move!
这题看似简单其实特别坑输入的坐标还有可能不相邻和超过范围。。。真是无节操坑
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 20;
char str
;
int judge(int x,int y);
int main()
{
while(scanf("%s",str[0])!=EOF)
{
for(int i=1; i<8; i++)
{
scanf(" %s",str[i]);
}
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
int flag=0;
if((abs(x1-x2)+abs(y2-y1)!=1)||(x1<1)||(x1>8)||(x2<1)||(x2>8)||(y1<1)||(y1>8)||(y2<1)||(y2>8))//技巧
{
flag=0;
}
else
{
char tmp;
tmp=str[x1-1][y1-1],str[x1-1][y1-1]=str[x2-1][y2-1],str[x2-1][y2-1]=tmp;
for(int i=0; i<8; i++)
{
for(int j=0; j<8; j++)
{
if(judge(i,j))
{
flag=1;
break;
}
}
if(flag==1)
{
break;
}
}
}
if(flag==1)
{
printf("Ok!\n");
}
else
{
printf("Illegal move!\n");
}
memset(str,0,sizeof(str));
}
return 0;
}
int judge(int x,int y)
{
if(y<6&&str[x][y+1]==str[x][y+2]&&str[x][y+1]==str[x][y])
{
return 1;
}
if(x<6&&str[x+1][y]==str[x+2][y]&&str[x+1][y]==str[x][y])
{
return 1;
}
return 0;
}
相关文章推荐
- 卡特兰数(Catalan Number)
- JavaScript高级程序设计(第3版)中文 高清 完整
- HDU 1052 Tian Ji -- The Horse Racing
- C++重载函数的实现小结(实战篇)
- Spring+Spring MVC+MyBatis(SSM)整合
- Javascript加载执行中的问题
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转
- 矩阵论还真有用:图片缩放旋转