热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Fling!

算法:深搜很不错的一道题!!!Flingisakindofpuzzlegamesavailableonphone.Thisg

算法:深搜

很不错的一道题!!!

Fling is a kind of puzzle games available on phone.
This game is played on a board with 7 rows and 8 columns. Each puzzle consists of a set of furballs placed on the board. To solved a puzzle, you need to remove the furballs from board until there is no more than one furball on the board. You do this by ´flinging´ furballs into other furballs, to knock them off the board. You can fling any furballs in four directions (up, left, right, down). The flung furball stops at the front grid of another one as soon as knocking it. And the knocked furball continues to rolling in the same direction until the last knocked one goes off the board. For instance, A furball at (0, 0) rolls right to the furball at (0, 5), then it will stop at (0, 4). Moreover, the latter will roll to right. You cannot fling a furball into a neighbouring furball, the one next to in any of four directions. However, it is permitted for a rolling ball knocks into a ball with a neighbour in that direction.



Input
The input contains multiple test cases.
For each case, the 7 lines with 8 characters describe the board. ´X´ represents a empty grid and ´O´ represents a grid with a furball in it. There are no more than 12 furballs in any board.
Each case separated by a blank line.

Output
For each case, print a line formatted as "CASE #NUM:", where NUM is the number of current case.
Then every ´fling´ prints a line. Each line contains two integers X, Y and a character Z. The flung furball is located at grid (X, Y), the top-left grid is (0, 0). And Z represents the direction this furball towards: U (Up), L (Left), R (Right) and D (Down);
Print a blank line between two cases.
You can assume that every puzzle could be solved.
If there are multiple solve sequences, print the smallest one. That is, Two sequences A (A1, A2, A3 ... An) and B (B1, B2, B3 ... Bn). Let k be the smallest number that Ak != Bk.
Define A (1) X in Ak (2) Y in Ak (3) Z in Ak The order of Z: U
Sample Input
XXXXXXXX
XXOXXXXX
XXXXXXXX
XXXXXXXX
XOXXXXOX
XXXXXXXX
XXXXXXXX

XXXXXXXX
XOXOXOOX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
Sample Output
CASE #1:
4 6 L
1 2 D

CASE #2:
1 1 R
1 4 L
1 3 R
代码:

#include #include #include #include #include #include using namespace std;char ch[10][10];int cur[4][2] = {{-1,0},{0,-1},{0,1},{1,0}}; //U、L、R、D char ch1[] = "ULRD";int n=7,m=8,cnt;int path[15];int pathc[15];int cmp(int bx,int by)
{ if(bx<0||by<0||bx>&#61;n||by>&#61;m) return 0; return 1;
} int dfs(int ax){if(ax&#61;&#61;cnt-1)return 1;int tx[15],ty[15],i,j,k,dx,dy;for( i&#61;0;i>ch[i];cnt&#61;0;for(i&#61;0;i


转载于:https://www.cnblogs.com/wangyumin/p/5323432.html


推荐阅读
author-avatar
mobiledu2502924733
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有