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. 简单使用PuTTy登录centos虚拟机

    博主刚刚开始学习Linux,想通过写博客的方式加深对linux学习的记忆 使用虚拟机安装精简版的linux后发现窗口字体太小,于是就想着通过PuTTy登录的方式解决 简单安装linux后 将linux ...

  2. git stash应用

    今天在看一个bug,之前一个分支的版本是正常的,在新的分支上上加了很多日志没找到原因,希望回溯到之前的版本,确定下从哪个提交引入的问题,但是还不想把现在的修改提交,也不希望在Git上看到当前修改的版本 ...

  3. filter-policy和AS-PATH-FILTER过滤BGP路由条目

    Filter-policy过滤BGP路由条目 一:根据项目需求搭建好拓扑图如下: 二:配置 1:对项目图做理论分析,首先RT1和RT2属于EBGP(不同自治系统之间的直连路由),而RT2和RT3属于I ...

  4. JQ 封装全选函数

    单击时触发效果: 如果有一个没有选中把全选的勾去了,如果select所有的都选中了,那就把全选勾上 html里: <div class="row cl"> <la ...

  5. python基础小知识,is和==的区别,编码和解码

    1.is和==的区别 1)id() 通过id()我们可以查看到一个变量表示的值在内存中的地址 >>> s1 = "Tanxu" >>> s2 = ...

  6. 复位自动ID的问题有兩種方法

    复位自动ID的问题 有兩種方法:      方法1:      truncate   table   你的表名   --這樣不但將數據刪除,而且可以重新置位identity屬性的字段.         ...

  7. node session会话

    会话机制: 浏览器-->服务器 浏览器<--服务器 (产生一个会话id,保存在cookie中) 浏览器-->服务器(服务器根据会话id关联到相应数据信息体data) var expr ...

  8. (长期更新)OI常用模板

    代码很简单的模板就不收录了. DFT 离散傅立叶变换 void dft(pdd *a,int l,bool r){ int i,j=l/2,k; for(i=1;i<l;++i){ if(i&l ...

  9. redhat6.4 安装Oracle11gR2 遇到的问题

    http://blog.sina.com.cn/s/blog_53a5865c0102e2u6.html   1.使用的时候出现一个错误: /lib/ld-linux.so.2: bad ELF in ...

  10. Hadoop启动后无法启动NodeManager

    在配置完Hadoop集群后,使用命令:“start-all.sh”进行启动集群.然后使用命令:“jps”查看进程启动情况,发现没有NodeManager 只需要使用命令:cd  /usr/local/ ...