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. 尚硅谷SpringBoot项目学习源码记录

    链接:https://pan.baidu.com/s/1aNUL1QlHMhDIFtWGhC1mtQ 密码:793v

  2. Java源码解析——集合框架(二)——ArrayBlockingQueue

    ArrayBlockingQueue源码解析 ArrayBlockingQueue是一个阻塞式的队列,继承自AbstractBlockingQueue,间接的实现了Queue接口和Collection ...

  3. ECSHOP和SHOPEX快递单号查询百世快递插件V8.6专版

    发布ECSHOP说明: ECSHOP快递物流单号查询插件特色 本ECSHOP快递物流单号跟踪插件提供国内外近2000家快递物流订单单号查询服务例如申通快递.顺丰快递.圆通快递.EMS快递.汇通快递.宅 ...

  4. 51定时器控制4各led,使用回调函数机制

    程序转载自51hei,经过自己的实际验证,多了一种编程的思路技能,回调函数的基本思想也是基于事件机制的,哪个事件来了, 就执行哪个事件. 程序中,最多四个子定时器,说明51的处理速度是不够的,在中断中 ...

  5. Python3 适合初学者学习的银行账户登录系统

    一.所用知识点: 1. for循环与if判断的结合 2. %s占位符的使用 3. 辅助标志的使用(标志位) 4. break的使用 二.代码示例: ''' 银行登录系统 ''' uname = &qu ...

  6. 杭电 1003 Max Sum (动态规划)

    参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> ...

  7. spring boot打包问题

    java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories ...

  8. ansible结合SHELL搭建自己的CD持续交付系统

    一. 设计出发点 因公司业务面临频繁的迭代上线,一日数次.仅仅依靠手工效率过低且易出错. 考虑搭建一套可以满足现有场景的上线系统. 二 .为何采用ansible+shell方式 1.可控性(完全自主拥 ...

  9. c# string.format和tostring()

    字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0:D3}", ...

  10. [Windows]_[C/C++]_[如何调试子进程]

    场景 1.VC++ 的程序A在启动程序C时, 如果需要调试程序C的话一般有两种, 一种是通过菜单 调试->附加到进程的方式来调试程序, 缺点就是这个进程必须先启动, 但是一启动的话有可能就执行了 ...