K. Fling

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
题意:

在一个7*8的板子上,有若干个球(小于12个,经测试最多11个)。你每次可以选择一个球向上下左右推动,

能推动的条件是推动的方向上有球但是不能粘在一起,中间必需得隔一个及以上的格子。然后你推动这个球后它

会一直在这个方向上滚动,直到碰到下一个球或者掉下板子去。如果碰到下一个球他的动能会传递下去,如果碰

到的球紧挨着另一个球就隔山打牛,而原来的球就停在碰到的球的前一个位置上。然后结束标志是板子上只剩一

个球。输出每次操作的球的坐标和推动的方向(ULRD)。

#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
char ch[][];
int cur[][] = {{-,},{,-},{,},{,}}; //U、L、R、D
char ch1[] = "ULRD";
int n=,m=,cnt;
int path[];int pathc[];
int cmp(int bx,int by)
{
if(bx<||by<||bx>=n||by>=m)
return ;
return ; } int dfs(int ax)
{
if(ax==cnt-)
return ; int tx[],ty[],i,j,k,dx,dy;
for( i=;i<n;i++)
{
for(j=;j<m;j++)
if(ch[i][j]=='O')
{ for(k=;k<;k++)
{
int mo=;int cd=;
dx=i+cur[k][];
dy=j+cur[k][];
if(ch[dx][dy]=='O')
continue;
while(cmp(dx,dy))
{
if(ch[dx][dy]=='O')
{
mo=;
tx[cd]=dx;
ty[cd++]=dy;
}
dx+=cur[k][];
dy+=cur[k][];
}
if(mo)
{
ch[i][j]='X';
for(int ii=;ii<cd;ii++)
{
ch[tx[ii]][ty[ii]]='X';
ch[tx[ii]-cur[k][]][ty[ii]-cur[k][]]='O';
} path[ax]=i*m+j;
pathc[ax]=k;
if(dfs(ax+)) return ;
ch[i][j]='O';
dx=i+cur[k][];
dy=j+cur[k][];
while(cmp(dx,dy))
{
if(ch[dx][dy]=='O')
ch[dx][dy]='X';
dx+=cur[k][];
dy+=cur[k][];
}
for(int ii=;ii<cd;ii++)
ch[tx[ii]][ty[ii]]='O';
}
}
}
}
return ;
}
int main()
{
int i,j,p=;
while(~scanf("%s",&ch[]))
{
for(i=;i<n;i++)
cin>>ch[i];
cnt=;
for(i=;i<n;i++)
for(j=;j<m;j++)
if(ch[i][j]=='O')
cnt++;
dfs();
if(p) cout<<endl;
cout<<"CASE #"<<++p<<":"<<endl;
for(i=;i<cnt-;i++)
cout<<path[i]/m<<" "<<path[i]%m<<" "<<ch1[pathc[i]]<<endl;
}
return ;
}

Fling——K的更多相关文章

  1. django模型操作

    Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表        

  2. Fling!

    算法:深搜 很不错的一道题!!! Fling is a kind of puzzle games available on phone. This game is played on a board ...

  3. hdu 3500 Fling (dfs)

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

  4. 基于改进人工蜂群算法的K均值聚类算法(附MATLAB版源代码)

    其实一直以来也没有准备在园子里发这样的文章,相对来说,算法改进放在园子里还是会稍稍显得格格不入.但是最近邮箱收到的几封邮件让我觉得有必要通过我的博客把过去做过的东西分享出去更给更多需要的人.从论文刊登 ...

  5. 【开源】专业K线绘制[K线主副图、趋势图、成交量、滚动、放大缩小、MACD、KDJ等)

    这是一个iOS项目雅黑深邃的K线的绘制. 实现功能包括K线主副图.趋势图.成交量.滚动.放大缩小.MACD.KDJ,长按显示辅助线等功能 预览图 最后的最后,这是项目的开源地址:https://git ...

  6. 找到第k个最小元----快速选择

    此算法借用快速排序算法. 这个快速选择算法主要利用递归调用,数组存储方式.包含3个文件,头文件QuickSelect.h,库函数QuickSelect.c,测试文件TestQuickSelect. 其 ...

  7. BZOJ 3110: [Zjoi2013]K大数查询 [树套树]

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6050  Solved: 2007[Submit][Sta ...

  8. 二次剩余、三次剩余、k次剩余

    今天研究了一下这块内容...首先是板子 #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  9. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

随机推荐

  1. 介绍n款计算机视觉库/人脸识别开源库/软件

    计算机视觉库 OpenCV OpenCV是Intel®开源计算机视觉库.它由一系列 C 函数和少量 C++ 类构成,实现了图像处理和计算机视觉方面的很多通用算法. OpenCV 拥有包括 300 多个 ...

  2. C# 使用 NPOI 库读写 Excel 文件

    NPOI 是开源的 POI 项目的.NET版,可以用来读写Excel,Word,PPT文件.在处理Excel文件上,NPOI 可以同时兼容 xls 和 xlsx.官网提供了一份 Examples,给出 ...

  3. Codeforces Beta Round #77 (Div. 1 Only) C. Volleyball (最短路)

    题目链接:http://codeforces.com/contest/95/problem/C 思路:首先dijkstra预处理出每个顶点到其他顶点的最短距离,然后如果该出租车到某个顶点的距离小于等于 ...

  4. Java学习笔记(七)——对象

    一.类与对象 1.类的定义 类就是模型,确定对象将会拥有的特征(属性)和行为(方法). 2.类的特点 (1)类是对象的类型 (2)具有相同属性和方法的一组对象的集合. 3.对象的属性: 对象具有的各种 ...

  5. (转载)如何借助KeePassX在Linux上管理多个密码

    转自:http://netsecurity.51cto.com/art/201311/417764.htm 如今,基于密码的身份验证在网上非常普遍,结果你恐怕数不清自己到底在使用多少个密码.实际上,据 ...

  6. 【项目经验】navicat工具 SQLServer数据库迁移MySQL

    新近领了一个任务,就是把SQL Server的数据库迁移到My Sql上,经过查资料,圆满完成任务.分享一下流程. 1.首先,在自己的My Sql数据库上新建一个数据库. 2.打开新建的My Sql数 ...

  7. Linux环境下搭建Tomcat+mysql+jdk

    Linux环境 1.下载并安装一个VMware workstation, 这个是虚拟机的平台(自行度娘下载~),虚拟机是在后面要在里面搭建Linux系统. 2.下载一个centos安装包,linux版 ...

  8. Laravel系列 目录结构

    Where Is The Models Directory? app directory by default 其中 app:,core code of your application, almos ...

  9. AngularJS学习之输入验证

    1.AngularJS可以验证表单和控件可以验证输入的数据: 2.输入验证:客户端不能确保用户输入数据的安全,所以服务器端的数据验证也是必须的: 3.应用实例: <! DOCTYPE html& ...

  10. fzu月赛 2203 单纵大法好 二分

    Accept: 8    Submit: 18Time Limit: 5000 mSec    Memory Limit : 65536 KB  Problem Description 人在做,天在看 ...