博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Zoj1628--Diamond(Dfs《暴力》)
阅读量:7211 次
发布时间:2019-06-29

本文共 3146 字,大约阅读时间需要 10 分钟。

Diamond

Time Limit: 2 Seconds     
Memory Limit: 65536 KB

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!

 


Author: PAN, Minghao

Source: ZOJ Monthly, June 2003

话说一不小心WA了一晚上, 我nm。

ac码:

#include 
#include
#include
using namespace std;char map[10][10];bool Dfs(int a, int b) //相当于往四个方向搜。{ int flag1 = 0, flag2 = 0; for(int i = a; i >= 1; i--) { if(map[i][b] == map[a][b]) flag1++; else break; } for(int i = a+1; i <= 8; i++) { if(map[i][b] == map[a][b]) flag1++; else break; } if(flag1 >= 3) return true; for(int i = b; i >= 1; i--) { if(map[a][i]==map[a][b]) flag2++; else break; } for(int i = b + 1; i <= 8; i++) { if(map[a][i]== map[a][b]) flag2++; else break; } if(flag2 >= 3) return true; return false;}int main(){ while(cin >> map[1][1]) { for(int i = 1; i <= 8; i++) for(int j = 1; j <= 8; j++) { if(i == 1 && j == 1) continue; else cin >> map[i][j]; } int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); if(abs(a-c) + abs(b-d) != 1){ //xiaojianzhi printf("Illegal move!\n"); continue; } char s; s = map[a][b];map[a][b] = map[c][d]; map[c][d] = s; // swap position. if(Dfs(a, b) || Dfs(c, d)) printf("Ok!\n"); else printf("Illegal move!\n"); } return 0; }

 

转载于:https://www.cnblogs.com/soTired/p/4759033.html

你可能感兴趣的文章
异常测试实践与梳理
查看>>
多者异也
查看>>
tf:'hello tensorflow'
查看>>
RedisConf2018记录--Day 1 sessions
查看>>
CentOS的el5, el6, el7代表什么
查看>>
柏林纪行(中):Node.js Collaboration Summit
查看>>
IT网络通信大变革时代来临 2016中国极客大奖为您找到风向标
查看>>
如何下载WDK
查看>>
硬纪元干货|镁客网萨向东:推动硬科技产业落地,助力传统产业升
查看>>
SSDT&Shadow Hook的实现,完整代码。可编译
查看>>
Spring4-自动装配Beans-通过注解@Autowired在构造方法上
查看>>
MapReduce编程(四) 求均值
查看>>
ASP.NET MVC在IIS6下部署的小技巧
查看>>
asp.net 递归删除文件夹及其子文件夹和所有文件[转]
查看>>
TCP端口状态说明ESTABLISHED、TIME_WAIT、 CLOSE_WAIT
查看>>
Bengio:我留在学术圈为全人类作贡献,而不是为某一个公司赚钱
查看>>
100多个经典常用的PHP功能插件大全实例演示和下载
查看>>
Mac 下iterm2配色方案(高亮)及显示分支
查看>>
使用<meta>来刷新网页效果
查看>>
VR为难民发声,传递人道主义精神
查看>>