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. 台式机上如何配置并使用苹果iPhone的耳机麦克风 并且麦克风开启降噪功能

    这个资料和技巧在网络上面很少有人分享,但是可能会有不少人需要这个东西.这里分享下经验.这也是一个困扰我很久的一个问题.因为买来了这个转接头,发现,录音的时候iPhone的耳机麦克风有很大的噪音无法消除 ...

  2. intellij IEDA 从svn拉环境到正常运行

    intellij IEDA  从svn拉环境到正常运行 1.svn拉项目 在项目选择界面点击Check out from Version Control 从中选择Subversion(SVN) 2.选 ...

  3. MySql指令的执行顺序

    1:From 2:On 3:Join 4:Where 5:Group by 5.1:函数 6:Having 7:Select 8:Distinct 9:Order by

  4. thinkphp5阿里大于短信接口

    function autumn_sendsms($tel,$stype){ $pd_go=true; if($tel==''){ $msg='手机号不能为空'; $pd_go=false; } if( ...

  5. PHP 使用程序进行数据库字典文件生成 导出数据库字典

    作为一个程序员肯定是不愿意写文档的!!! 尤其最麻烦的数据库字典文档 所以偷懒写了一个PHP程序来进行数据库字典导出 记录一下  以免以后忘记 //使用的是Laravel框架 可以转换成原生导出$ta ...

  6. Cython中def,cdef,cpdef的区别

    这是我的第一篇翻译,希望大家多多给出意见和建议. 如有转载,请注明出处. 原文来自:https://stackoverflow.com/questions/28362009/definition-of ...

  7. nginx配置SSL证书/强制跳转与非强制跳转

    支持强制跳转HTTPS server { listen 80; server_name www.test.com; rewrite ^(.*)$ https://${server_name}$1 pe ...

  8. Python协程中使用上下文

    在Python 3.7中,asyncio 协程加入了对上下文的支持.使用上下文就可以在一些场景下隐式地传递变量,比如数据库连接session等,而不需要在所有方法调用显示地传递这些变量.使用得当的话, ...

  9. 计蒜客-----跳跃游戏(C语言)

    /********************************************************给定一个非负整数数组,假定你的初始位置为数组第一个下标.数组中的每个元素代表你在那个位 ...

  10. Kubernetes-设计理念(三)

    Kubernetes设计理念与分布式系统 分析和理解Kubernetes的设计理念可以使我们更深入的了解Kubernetes系统,更好的利用它管理分布式部署的云原生应用,另一方面也可以让我们借鉴其在分 ...