Fling——K
K. Fling
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
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
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的更多相关文章
- django模型操作
Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表
- Fling!
算法:深搜 很不错的一道题!!! Fling is a kind of puzzle games available on phone. This game is played on a board ...
- hdu 3500 Fling (dfs)
Fling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...
- 基于改进人工蜂群算法的K均值聚类算法(附MATLAB版源代码)
其实一直以来也没有准备在园子里发这样的文章,相对来说,算法改进放在园子里还是会稍稍显得格格不入.但是最近邮箱收到的几封邮件让我觉得有必要通过我的博客把过去做过的东西分享出去更给更多需要的人.从论文刊登 ...
- 【开源】专业K线绘制[K线主副图、趋势图、成交量、滚动、放大缩小、MACD、KDJ等)
这是一个iOS项目雅黑深邃的K线的绘制. 实现功能包括K线主副图.趋势图.成交量.滚动.放大缩小.MACD.KDJ,长按显示辅助线等功能 预览图 最后的最后,这是项目的开源地址:https://git ...
- 找到第k个最小元----快速选择
此算法借用快速排序算法. 这个快速选择算法主要利用递归调用,数组存储方式.包含3个文件,头文件QuickSelect.h,库函数QuickSelect.c,测试文件TestQuickSelect. 其 ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- 二次剩余、三次剩余、k次剩余
今天研究了一下这块内容...首先是板子 #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- [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 ...
随机推荐
- Windows和Windows Phone应用终于可以使用FFmpeg了
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:曾经在Windows Phone上想开发一个支持多种格式的媒体播放器是比较困难的一件事 ...
- 如何在ASP.NET 5中使用ADO.NET
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ASP.NET 5是一个全新的平台,在这个平台上也带来一些全新的函数库.不过这并非意味 ...
- 调整vbox虚拟机下的linux全屏模式及分辨率
>>Step1 在VirtualBox菜单栏中选择[设备]->[安装增强功能] >>Step2 点击右上角的[齿轮]图标,然后选择[Log Out],重新登录即可 lin ...
- 第六篇:在SOUI中用九宫格拉伸方式显示一个图片资源
SOUI的初学者刚开始可能难以搞清楚在SOUI中显示一个图片资源的流程,这里做一个简单的示范. 首先我们准备好一张图,以下图为例. 第一步,我们首先把这个图片文件复制到demo的uires目录下,新建 ...
- 在Salesforce中进行Report和Dashboard的配置
用Report和Dashboard去图形化比较不同Object的信息是一个十分普遍的需求,当然我们可以完全用Visual Page和Classes去自定义对应的Report和Dashboard的功能. ...
- barabasilab-networkScience学习笔记2-图理论
第一次接触复杂性科学是在一本叫think complexity的书上,Allen博士很好的讲述了数据结构与复杂性科学,barabasi是一个知名的复杂性网络科学家,barabasilab则是他所主导的 ...
- 2015腾讯web前端笔试题
1 请实现,鼠标点击页面中的任意标签,alert该标签的名称.(注意兼容性) 2 请指出一下代码的性能问题,并经行优化. var info="腾讯拍拍网(www.paipai.com)是 ...
- java集群技术(转)
来源:http://blog.csdn.net/cdh1213/article/details/21443239 序言 越来越多的关键应用运行在J2EE(Java2, Enterprise Editi ...
- 【微信Java开发 --番外篇】错误解析
虽然在微信开发过程中,会有微信公众平台开发者文档中的<全局返回码>作为错误的参考对比:但是依旧的,会觉得有时候的问题莫名其妙.[注:本人使用weixin-java-tools进行开发] 下 ...
- PHP 配置文件详解(php.ini 详解 )
[PHP] ; PHP还是一个不断发展的工具,其功能还在不断地删减 ; 而php.ini的设置更改可以反映出相当的变化, ; 在使用新的PHP版本前,研究一下php.ini会有好处的 ;;;;;;;; ...