算法:深搜

很不错的一道题!!!

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 <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <stdio.h>
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<n;i++)
{
for(j=0;j<m;j++)
if(ch[i][j]=='O')
{ for(k=0;k<4;k++)
{
int mo=0;int cd=0;
dx=i+cur[k][0];
dy=j+cur[k][1];
if(ch[dx][dy]=='O')
continue;
while(cmp(dx,dy))
{
if(ch[dx][dy]=='O')
{
mo=1;
tx[cd]=dx;
ty[cd++]=dy;
}
dx+=cur[k][0];
dy+=cur[k][1];
}
if(mo)
{
ch[i][j]='X';
for(int ii=0;ii<cd;ii++)
{
ch[tx[ii]][ty[ii]]='X';
ch[tx[ii]-cur[k][0]][ty[ii]-cur[k][1]]='O';
} path[ax]=i*m+j;
pathc[ax]=k;
if(dfs(ax+1)) return 1;
ch[i][j]='O';
dx=i+cur[k][0];
dy=j+cur[k][1];
while(cmp(dx,dy))
{
if(ch[dx][dy]=='O')
ch[dx][dy]='X';
dx+=cur[k][0];
dy+=cur[k][1];
}
for(int ii=0;ii<cd;ii++)
ch[tx[ii]][ty[ii]]='O';
}
}
}
}
return 0;
}
int main()
{
int i,j,p=0;
while(~scanf("%s",&ch[0]))
{
for(i=1;i<n;i++)
cin>>ch[i];
cnt=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(ch[i][j]=='O')
cnt++;
dfs(0);
if(p) cout<<endl;
cout<<"CASE #"<<++p<<":"<<endl;
for(i=0;i<cnt-1;i++)
cout<<path[i]/m<<" "<<path[i]%m<<" "<<ch1[pathc[i]]<<endl;
}
return 0;
}

Fling!的更多相关文章

  1. LIstView 滚动 异步 加载更多 mono for android ScrollStateChanged ScrollState.Idle; Fling;TouchScroll

    今天项目需要实现一下列表的分页加载 找到了Listview的ScrollStateChanged方法. 和大家分享一下 //先找到Listview ListView order = FindViewB ...

  2. Fling——K

    K. Fling Fling is a kind of puzzle games available on phone.This game is played on a board with 7 ro ...

  3. Android: 触屏fling/scroll/drag的区别及其详细过程

    Google了一下,终于搞清了touch screen下的几种操作模式(对应的是事件). 对于一个view, 常用的操作有点击(click)和长按(long press)二种.实际上,这些操作类型是A ...

  4. Android “swipe” vs “fling”

    onFling will get executed when a user makes a "fling" motion, and said motion has a veloci ...

  5. hdu 3500 Fling (dfs)

    Fling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  6. android问题及其解决-优化listView卡顿和怎样禁用ListView的fling

    问题解决-优化listView卡顿和怎样禁用ListView的fling 前戏非常长,转载请保留出处:http://blog.csdn.net/u012123160/article/details/4 ...

  7. Scroller——startScroll、fling(惯性滑动)

    Scroller主要用于平滑滚动,主要使用的滚动方法有:startScroll.fling. startScroll(int startX, int startY, int dx, int dy, i ...

  8. 【HDOJ】3500 Fling

    题意巨难懂.简言之,就是球互相碰撞时,主动碰撞的球将会停止,另一个球将沿着碰撞方向继续移动,不断碰撞.但是无法弹射紧挨着的球,但是若a弹射b,bc相邻,这种情况b可以弹射c. #include < ...

  9. android自定义控件一站式入门

    自定义控件 Android系统提供了一系列UI相关的类来帮助我们构造app的界面,以及完成交互的处理. 一般的,所有可以在窗口中被展示的UI对象类型,最终都是继承自View的类,这包括展示最终内容的非 ...

随机推荐

  1. IEnumerable中的 Any方法

    IEnumerable类中的 Any方法,表示集合中有任何一元素满足条件,返回就true , 该方法有两个重载 1. 不带任何参数,表示集合中有元素 2. 参入一个 Func<TSource, ...

  2. js本地存储解决方案(localStorage与userData)

    WEB应用的快速发展,是的本地存储一些数据也成为一种重要的需求,实现的方案也有很多,最普通的就是cookie了,大家也经常都用,但是cookie的缺点是显而易见的,其他的方案比如:IE6以上的user ...

  3. Indy10 即时通讯Demo

    最近闲来无事,重新学习了Indy10,顺手写了一段即时通讯代码.与上次写的笔记有不同之处,但差别不大. 未研究过TCP打洞技术,所以下面的代码采用的是  客户端--服务器--客户端  模式,也就是服务 ...

  4. python命令行运行在win和Linux系统的不同

    今天,在完成一个小的python习题,习题的主要内容是读取一个帮助模块,并保存到本地文件. 知道是用pydoc进行模块的读取,但是在windows系统下,调用os模块之后,结果总是为空. 核心语句: ...

  5. 05 - 替换vtkDataObject中的Update方法 VTK 6.0 迁移

    VTK6 引入了许多不兼容的变.其中之一是删除vtkDataObject中所有有关管道的方法.下面讨论update方法并提供迁移现有代码的建议. Update() vtkDataObject::Upd ...

  6. 当fixed元素相互嵌套时chrome下父元素会影响子元素的层叠关系

    问题:fixed元素被另一个fixed元素包含的时候在chrome下fixed子元素的定位会受到父元素的影响. demo(http://jsbin.com/qumah/1): <!DOCTYPE ...

  7. Android的两种菜单

    Android子菜单和选项菜单与上下文菜单的实现 菜单在Android开发中必不可少,可是要怎么实现各种菜单呢?是不是很头疼呢?下面我就来介绍一下: 1. 选项菜单和子菜单的实现 选项菜单:最常规的菜 ...

  8. C++中基于Crt的内存泄漏检测(重载new和delete,记录在Map里)

    尽管这个概念已经让人说滥了 ,还是想简单记录一下, 以备以后查询. #ifdef _DEBUG#define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FIL ...

  9. 将大型 Page Blob 的页范围进行分段

     Windows Azure 存储支持一种 Blob 类型,即 Page Blob.Page Blob 通过仅将已写入但未清除的页存入物理存储, 来有效存储稀疏数据.每页大小为 512 字节.Ge ...

  10. App项目升级Xcode7&iOS9(续) - This bundle is invalid. The bundle identifier contains disallowed characters

    金田 iOS 9发布已经有2月有余,现在Xcode已经有升级到Xcode7.1,开发环境安装等一系列相关的流程,以及Xcode 7 & iOS 9升级相关的一些部分,在这里就不再多加赘述(详见 ...