博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Fling!
阅读量:6503 次
发布时间:2019-06-24

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

算法:深搜

很不错的一道题!!!

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 < B :
(1) X in Ak < X in Bk;
(2) Y in Ak < Y in Bk and X in Ak = X in Bk;
(3) Z in Ak < Z in Bk and (X,Y) in Ak = (X,Y) in Bk;
The order of Z: U < L < R < D.
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>=n||by>=m) return 0; return 1; } int dfs(int ax) { if(ax==cnt-1) return 1; int tx[15],ty[15],i,j,k,dx,dy; for( i=0;i
>ch[i]; cnt=0; for(i=0;i

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

你可能感兴趣的文章
一。简单搭建Spring框架及用JUnit测试。
查看>>
我的友情链接
查看>>
关于iOS版Citrix Receiver不支持文件上传下载的说明
查看>>
“沙场”体会一
查看>>
Newstart HA常见使用场景
查看>>
为win7/8/8.1/10添加开机启动项
查看>>
Linux防火墙【Centos7】
查看>>
IOS UDP通讯
查看>>
银行IT部门科技管理流程管控工作发展之路
查看>>
centos7.x的磁盘限额配置
查看>>
jquery判断checkbox(复选框)是否选中
查看>>
域网络与工作组网络
查看>>
让Python与R翩翩共舞
查看>>
Kubernetes v1.10.x+HA 全手动安装教程
查看>>
SpringMVC与fastjson整合并同时解决中文乱码问题
查看>>
Python格式字符串
查看>>
阿里云服务器双十一攻略,撸1折云服务器。
查看>>
解决Cannot change version of project facet Dynamic
查看>>
数据平台之企业营销管理与分析平台建设
查看>>
#pragma once和#ifndef的区别
查看>>