hdu 3500 Fling (dfs)
Fling
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 354 Accepted Submission(s): 143
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.
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.
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.
2821 | Pusher |
//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)的更多相关文章
- HDU.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- hdu 3500 DFS(限定)
Fling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
- hdu 1175 连连看 DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 解题思路:从出发点开始DFS.出发点与终点中间只能通过0相连,或者直接相连,判断能否找出这样的路 ...
- HDU 5547 Sudoku(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...
- F - Auxiliary Set HDU - 5927 (dfs判断lca)
题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...
- hdu 4714 树+DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 本来想直接求树的直径,再得出答案,后来发现是错的. 思路:任选一个点进行DFS,对于一棵以点u为 ...
- HDU 6228 - Tree - [DFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
随机推荐
- PHP生成一个六位数的邀请码
PHP生成一个六位数的邀请码 $unique_no = substr(base_convert(md5(uniqid(md5(microtime(true)),true)), 16, 10), 0, ...
- Centos6 Ruby 1.8.7升级至Ruby 2.3.1的方法
本文章地址:https://www.cnblogs.com/erbiao/p/9117018.html#现在的版本 [root@hd4 /]# ruby --version ruby (-- patc ...
- Java : 多态表现:静态绑定与动态绑定(向上转型的运行机制)
本来想自己写写的,但是看到有人分析的可以说是很清晰了,故转过来. 原文地址:http://www.cnblogs.com/ygj0930/p/6554103.html 一:绑定 把一个方法与其所在的类 ...
- 利用PHP str_replace()函数替换符合百度MIP内容标准
了解过百度MIP的同学都知道(什么?你不知道什么是百度MIP?就是移动网页加速器鸭
- 安装java 和 eclipse
昨天安装eclipse出现个问题, 安装完了创建第一个项目目录的时候弹窗报错an ......什么什么, 百度一堆没有用,后来发现是jdk12不支持,换了jdk8就可以了, 然后eclipse安装py ...
- ADB工具的安装
1.Windows ADB工具下载地址: https://developer.android.google.cn/studio/releases/platform-tools ADB工具官网教程: h ...
- python2.7练习小例子(十九)
19):题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下,求它在第10次落地时,共经过多少米?第10次反弹多高? #!/usr/bin/python # -*- codi ...
- Python进程、线程、协程及IO多路复用
详情戳击下方链接 Python之进程.线程.协程 python之IO多路复用
- 名片管理系统demo
# 定义一个列表,用来储存名片 def cardInfors(): # 打印功能提示 print('欢迎使用名片管理系统v6.6.6') print('1:添加一个名片') print('2:删除一个 ...
- Python全栈 MongoDB 数据库(聚合、二进制、GridFS、pymongo模块)
断网了2天 今天补上 聚合操作: 对文档的信息进行整理统计的操作 返回:统计后的文档集合 db.collection.aggregate() 功能:聚合函数,完成聚合操作 参数:聚合条件,配 ...