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 ...
随机推荐
- Socket编程注意接收缓冲区大小
转自:http://www.cnblogs.com/ITBread/p/3900254.html 最近在做一个udp升级程序,因文件有点大,需要将程序分成多个包发送,每次发送一个包,收到回复后发送下一 ...
- iOS中图片动画的三种模式及基本的代码实现
-(void)play { //第一种图片动画模式 头尾方式 //头尾方式 [UIView beginAnimations:nil context:nil];//动画开始 [UIView setAni ...
- linux常用命令和选项
(1)比较两个文件. diff filename1 filename2 -y -W number; -y 并列格式输出 -W 并列格式输出时指定的列宽 (2)linux下抓包 tcpdump有三类关键 ...
- 【项目经验】 Html Select 遇上 Easyui
一.背景: 当我在做课表选择触发事件的时候,我发现了一个问题,就是我们直接用的easyui-combobox里面的的绑定事件(onchange)貌似触发不了,这是为什么呢? 二.结论及方法 .原始方法 ...
- 在 SQL Server 中查询EXCEL 表中的数据遇到的各种问题
SELECT * FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="D:\KK.xls";User ID=A ...
- 简单的c#插件框架
插件式架构,一种全新的.开放性的.高扩展性的架构体系.插件式架构设计近年来非常流行,基于插件的设计好处很多,把扩展功能从框架中剥离出来,降低了框架的复杂度,让框架更容易实现.扩展功能与框架以一种很松的 ...
- Uva442 hdu 1082 Matrix Chain Multiplication
要注意取出来的时候 先取出q的是后面那个矩阵 后取出p的是前面的矩阵 所以是判断 p.a == q.b #include <iostream> #include <stack> ...
- express-18 路由
简介 路由是网站或Web服务中最重要的一个方面:路由是将请求(由URL和HTTP方法指定)路由到处理它们的代码去的一种机制. 路由过去是基于文件的,这很简单,但不灵活. IA 是指内容的概念性组织.在 ...
- 线段树(区间操作) POJ 3325 Help with Intervals
题目传送门 题意:四种集合的操作,对应区间的01,问最后存在集合存在的区间. 分析:U T [l, r]填充1; I T [0, l), (r, N]填充0; D T [l, r]填充0; C T[0 ...
- Android自动化测试 - MonkeyRunner(一)介绍
MonkeyRunner介绍: MonkeyRunner是Google提供的一个基于坐标点的Android黑盒自动化测试工具. Monkeyrunner工具提供了一套API让用户/测试人员来调用,调用 ...