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 ...
随机推荐
- hdu 3709 数位dp
数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...
- 第十七篇:使用窗口的cache属性加速SOUI的渲染
内容渲染速度是决定一个UI成败的关键.无论UI做得多华丽,没有速度都没有意义. 在MFC,WTL等开发框架下,每个控件都是一个窗口,窗口只需要画前景,背景.因为窗口之间的内容不需要做混合,一个子窗口的 ...
- 程序员必懂:javaweb三大框架知识点总结
原文链接:http://www.cnblogs.com/SXTkaifa/p/5968631.html javaweb三大框架知识点总结 一.Struts2的总结 1.Struts 2的工作流程,从请 ...
- 数据库ORM框架GreenDao
常用的数据库: 1). Sql Server2). Access3). Oracle4). Sysbase5). MySql6). Informix7). FoxPro8). PostgreSQL9) ...
- java Clone使用方法详解
java"指针" Java语言的一个优点就是取消了指针的概念,但也导致了许多程序员在编程中常常忽略了对象与引用的区别,本文会试图澄清这一概念.并且由于Java不能 通过 ...
- Android学习系列(40)--Android主题和样式之系统篇(下)
11)Widget样式(Widget Style) 特别说明,此处定义大量的系统内置控件的样式,对于重写原生控件的样式具有很大的参考价值. <!-- Widget styles --> & ...
- light oj 1422 Halloween Costumes (区间dp)
题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...
- HTML DOM学习之三
1.创建新的HTML元素:appendChild(); 如需向HTML DOM添加元素,首先必须创建该元素,然后把它追加到已有的元素上: <div id="div1"> ...
- 17243 Huzi酱和他的俄罗斯套娃(贪心)
时间限制:500MS 内存限制:65535K 提交次数:15 通过次数:4 收入:12 题型: 编程题 语言: C++;C Description Huzi酱是个非常贪玩的人,除了魔方他还喜欢各 ...
- 【CLR in c#】属性
1.无参属性 1.为什么有字段还需要属性呢? 因为字段很容易写出不恰当的代码,破坏对象的状态,比如Age=-1.人的年纪不可能为负数.使用属性后你可以缓存某些值或者推迟创建一些内部对象,你可以以线程安 ...