Fling

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 354    Accepted Submission(s): 143

Problem Description
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
 
Author
EvilSeraph
 
Source
 
Recommend
zhouzeyong   |   We have carefully selected several similar problems for you:  3504 3506 3507 3501 3502 
 
 
这题和hdu

2821 Pusher
类似。
开始时不知道怎么处理比较好,先打算用个图保存,然后每个’O‘点另用数组保存,再深搜保存的点,这是处于对时间复杂度的优化;后来发现很难实现,于是就用下面这种方法,
比较暴力,直接暴力7*8的图,这题和之前做的2821 Pusher有点类似,而且数据也不难过,就是写的时候出了点小问题,后来1Y了,感觉还行。
 
 
 //625MS    248K    2295 B    G++
#include<stdio.h>
#include<string.h>
char g[][];
int ans[][];
char op[]="ULRD";
int mov[][]={-,,,-,,,,};
int n,flag;
int judge(int x,int y)
{
if(x>= && x< && y>= && y<) return ;
return ;
}
void dfs(int cnt)
{
if(cnt==n-) flag=;
if(flag) return;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(g[i][j]=='O'){
for(int k=;k<;k++){
int x=i;
int y=j;
if(!judge(x+mov[k][],y+mov[k][]) || g[x+mov[k][]][y+mov[k][]]=='O') continue;
int tx[],ty[],tt=;
while(judge(x,y)){
if(g[x][y]=='O'){
tx[tt]=x;
ty[tt++]=y;
}
x+=mov[k][];
y+=mov[k][];
}
if(tt==) continue; for(int ii=;ii<tt;ii++){
g[tx[ii-]][ty[ii-]]='X';
g[tx[ii]-mov[k][]][ty[ii]-mov[k][]]='O';
}
g[tx[tt-]][ty[tt-]]='X';
ans[cnt][]=i;
ans[cnt][]=j;
ans[cnt][]=k; dfs(cnt+);
if(flag) return; x=i;y=j;
while(judge(x,y)){
g[x][y]='X';
x+=mov[k][];
y+=mov[k][];
}
for(int ii=;ii<tt;ii++)
g[tx[ii]][ty[ii]]='O';
}
}
return;
}
int main(void)
{
int m,k=;
while(scanf("%s",g[])!=EOF)
{
for(int i=;i<;i++) scanf("%s",g[i]);
if(k>) printf("\n");
n=;
flag=;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(g[i][j]=='O')
n++;
dfs();
printf("CASE #%d:\n",k++);
for(int i=;i<n-;i++){
printf("%d %d %c\n",ans[i][],ans[i][],op[ans[i][]]);
}
}
return ;
}

hdu 3500 Fling (dfs)的更多相关文章

  1. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  2. hdu 3500 DFS(限定)

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

  3. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  4. hdu 4499 Cannon dfs

    Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...

  5. hdu 1175 连连看 DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 解题思路:从出发点开始DFS.出发点与终点中间只能通过0相连,或者直接相连,判断能否找出这样的路 ...

  6. HDU 5547 Sudoku(DFS)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...

  7. F - Auxiliary Set HDU - 5927 (dfs判断lca)

    题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...

  8. hdu 4714 树+DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 本来想直接求树的直径,再得出答案,后来发现是错的. 思路:任选一个点进行DFS,对于一棵以点u为 ...

  9. HDU 6228 - Tree - [DFS]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

随机推荐

  1. 主流浏览器内核,以及CSS3前缀识别码

    现在国内常见的浏览器有:IE.Firefox.QQ浏览器.Safari.Opera.Google Chrome.百度浏览器.搜狗浏览器.猎豹浏览器.360浏览器.UC浏览器.遨游浏览器.世界之窗浏览器 ...

  2. struts2架构网站漏洞修复详情与利用漏洞修复方案

    struts2从开发出来到现在,很多互联网企业,公司,平台都在使用apache struts2系统来开发网站,以及应用系统,这几年来因为使用较多,被攻击者挖掘出来的struts2漏洞也越来越,从最一开 ...

  3. SPFA算法(2) POJ 1511 Invitation Cards

    原题: Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 31230   Accepted: ...

  4. windows下subversion服务器搭建

    一.下载subversion服务器端和客户端软件 1.subversion下载地址:http://subversion.tigris.org/ 2.svn比较流行的客户端Tortoisesvn下载地址 ...

  5. struts2官方 中文教程 系列八:异常处理

    在本教程中,我们将探讨如何启用Struts 2框架处理web应用程序生成的任何未捕获的异常.Struts 2提供了健壮的异常处理,包括能够自动记录任何未捕获的异常,并将用户重定向到错误web页面. 贴 ...

  6. ActiveMQ测试实例

    ActiveMQ的安装与启动 1 下载ActiveMQ:http://activemq.apache.org/download.html 2 下载后解压到任意文件夹,解压后文件夹内的目录为: 3 进入 ...

  7. 环境变量 - JDK

    Linux 1. 备份并编辑配置文件 # cp /etc/profile /etc/profile.bak # vi /etc/profile 2. 设置JDK环境变量 export JAVA_HOM ...

  8. c++ list_iterator demo

    #include <iostream> #include <list> using namespace std; typedef list<int> Integer ...

  9. 用起来超爽的Maven——进阶篇

    以后随着使用的maven的频率增加,此文件会越来越大,也是为什么需要把默认C:\Users\Administrator\.m2 \repository目录改变为D:/OpenSources/repos ...

  10. android中activity,window,view之间的关系

    activity:控制单元 window:承载模型 view:显示视图 几个小tip: 1.一个 Activity 构造的时候一定会构造一个 Window(PhoneWindow),并且只有一个 2. ...