POJ-3009 Curling 2.0 解题报告

【POJ3009 - Curling】 解题报告+思路+代码+教训(看别人的报告过的) #include #include #include #include #define INPUT /** Problem : poj3009 看别人的报告过得,代码基本上相同,因为实在不会了 Begin Time: 11th/3/2012 7:28 p.m. End Time: 11th/3/2012 11:10 p.m. 解题报告:http://blog.csdn.net/harder 阅读详情

Description

On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to the goal with the minimum number of moves.

Fig. 1 shows an example of a game board. Some squares may be occupied with blocks. There are two special squares namely the start and the goal, which are not occupied with blocks. (These two squares are distinct.) Once the stone begins to move, it will proceed until it hits a block. In order to bring the stone to the goal, you may have to stop the stone by hitting it against a block, and throw again.


Fig. 1: Example of board (S: start, G: goal)

The movement of the stone obeys the following rules:

  • At the beginning, the stone stands still at the start square.
  • The movements of the stone are restricted to x and y directions. Diagonal moves are prohibited.
  • When the stone stands still, you can make it moving by throwing it. You may throw it to any direction unless it is blocked immediately(Fig. 2(a)).
  • Once thrown, the stone keeps moving to the same direction until one of the following occurs:
    • The stone hits a block (Fig. 2(b), (c)).
      • The stone stops at the square next to the block it hit.
      • The block disappears.
    • The stone gets out of the board.
      • The game ends in failure.
    • The stone reaches the goal square.
      • The stone stops there and the game ends in success.
  • You cannot throw the stone more than 10 times in a game. If the stone does not reach the goal in 10 moves, the game ends in failure.


Fig. 2: Stone movements

Under the rules, we would like to know whether the stone at the start can reach the goal and, if yes, the minimum number of moves required.

With the initial configuration shown in Fig. 1, 4 moves are required to bring the stone from the start to the goal. The route is shown in Fig. 3(a). Notice when the stone reaches the goal, the board configuration has changed as in Fig. 3(b).


Fig. 3: The solution for Fig. D-1 and the final board configuration

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets never exceeds 100.

Each dataset is formatted as follows.

the width(=w) and the height(=h) of the board 
First row of the board
 
... 
h-th row of the board

The width and the height of the board satisfy: 2 <= w <= 20, 1 <= h <= 20.

Each line consists of w decimal numbers delimited by a space. The number describes the status of the corresponding square.

0vacant square
1block
2start position
3goal position

The dataset for Fig. D-1 is as follows:

6 6 
1 0 0 2 1 0 
1 1 0 0 0 0 
0 0 0 0 0 3 
0 0 0 0 0 0 
1 0 0 0 0 1 
0 1 1 1 1 1

Output

For each dataset, print a line having a decimal integer indicating the minimum number of moves along a route from the start to the goal. If there are no such routes, print -1 instead. Each line should not have any character other than this number.

Sample Input

2 1
3 2
6 6
1 0 0 2 1 0
1 1 0 0 0 0
0 0 0 0 0 3
0 0 0 0 0 0
1 0 0 0 0 1
0 1 1 1 1 1
6 1
1 1 2 1 1 3
6 1
1 0 2 1 1 3
12 1
2 0 1 1 1 1 1 1 1 1 1 3
13 1
2 0 1 1 1 1 1 1 1 1 1 1 3
0 0

Sample Output

1
4
-1
4
10
-1

       题目链接:http://poj.org/problem?id=3009

       解法类型:DFS

       解题思路:直接按照题目要求进行深度优先搜索即可。从起点开始,分别从一个方向搜索下去,如果搜索到目标,则返回1,如果出界或者移动次数大于十,就跳过此次搜索,搜索下一个方向,直到所有的都搜索一遍,最后的min就是最小值。

       算法实现:

//STATUS:C++_AC_141MS_164K
#include<stdio.h>
const int MAXN=30;
int DFS(int x,int y,int tot);
char map[MAXN][MAXN];
int x1,y1,x2,y2,w,h,min,
dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int main()
{
//	freopen("in.txt","r",stdin);
	int i,j;
	while( scanf("%d%d",&w,&h) && w&&h )
	{
		min=0x7fffffff;

		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				scanf("%d",&map[i][j]);
				if(map[i][j]==2)x1=i,y1=j;
				else if(map[i][j]==3)x2=i,y2=j;
			}
		}

		DFS(x1,y1,0);

		printf("%d\n",min<=10?min:-1);
	}
	return 0;
}

int DFS(int x,int y,int tot)
{
	int i,nx,ny;
	for(i=0;i<4;i++){
		nx=x+dx[i],ny=y+dy[i];
		if(map[nx][ny]!=1 && nx>=0&&nx<h && ny>=0&&ny<w){  //判断方向
			if(tot+1>10)continue; //搜索失败continue
			do{                                                 //搜直线
				if(map[nx][ny]==3){if(tot+1<min)min=tot+1;return 1;}  //search succeed
				nx=nx+dx[i],ny=ny+dy[i];
			}while(map[nx][ny]!=1 && nx>=0&&nx<h && ny>=0&&ny<w);
		}
		else continue;  //nx,ny方向为block
		if(nx==h||nx<0 || ny==w||ny<0)continue; //出边界continue

		map[nx][ny]=0;  //block变为vacant
		DFS(nx-dx[i],ny-dy[i],tot+1);
		map[nx][ny]=1;  //vacant变为block
	}
	return 0;  //搜索失败
}

 
 
 

        
【poj 3009】Curling 2.0 中文题意&题解&代码(C++) poj dfs 阅读详情

相关推荐

【题解】POJ 3009 Curling2.0(DFS)

POJ 3009 Curling2.0 https://vjudge.net/problem/POJ-3009 题意 冰壶游戏,在一个游戏板上进行,板上有一个起点和一个终点并且有许多砖块,问冰壶从起点到终点最少要用的步数。 细则: 开始时,冰壶静止于起点。 冰壶静止时,你可以让它向上下左右移动,并且移动方向上的相邻点不能有砖块,如图a。 冰壶移动中无法主动停下,除非如下几种情况: ...

bu_shushu的博客 322

Curling 2.0

Problem Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on wh

Orz 401

掌握POJ3009-Curling 2.0:DFS、向量、回溯与剪枝的实战运用

深度优先搜索算法是一种沿着树的分支进行探索直到末端,然后回溯到上一个节点继续探索的过程。它适用于各种图遍历场景,比如解决迷宫问题、拓扑排序以及求解连通性问题等。std::vector定义于头文件中,它封装了一个动态数组,并提供了一系列成员函数来管理这个数组。创建一个std::vector对象可以使用不同的构造函数来完成。// 创建一个空的vector// 创建一个有5个整数元素,初始值都是0的vector// 创建一个有5个整数元素,初始值都是1的vector。

weixin_28931507的博客 861

poj3009

Curling 2.0 Time Limit:1000MS Memory Limit:65536K Total Submissions:5175 Accepted:2130 Description On Planet MM-21, after their Olympic games this year, c...

weixin_33726313的博客 345

POJ 3009 Curling 2.0 解题报告

业余爱好。所以,算法不一定好,CODING也不一定佳,效率不一定高,只是能通过online judge而已。

Aruba无线控制器实战:如何用Client Match优化企业办公区漫游(附SNR调优技巧)

本文深入解析了如何利用Aruba无线控制器的Client Match功能优化企业办公区无线漫游体验。通过实战配置,详细阐述了基于SNR(信噪比)的精细化调优策略,包括阈值设定、负载均衡与场景化参数调整,旨在解决终端粘滞、乒乓漫游等问题,实现智能、平滑的无缝漫游。

weixin_28318011的博客 230

POJ3009 Curling 2.0【DFS】

  On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is m...

海岛Blog 1136

深入解析TI C2000 ePWM模块:峰值电流模式Buck与LLC谐振变换器实战配置

脉宽调制(PWM)技术是电力电子与数字电源控制的核心,它通过调节开关信号的占空比或频率,实现对功率变换器输出电压、电流的精确控制。其基本原理是利用微控制器内部的定时器和比较器,生成具有特定时序的方波信号,驱动功率开关器件。这项技术的核心价值在于将复杂的模拟控制环路数字化,从而提升系统的可控性、灵活性和可靠性。在电机驱动、不间断电源(UPS)、服务器电源和新能源逆变器等广泛应用场景中,PWM技术都是实现高效能量转换的基石。本文聚焦于德州仪器(TI)C2000系列微控制器中功能强大的增强型PWM(ePWM)模块

weixin_30410119的博客 345

POJ 3009 Curling 2.0【带回溯DFS】

On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is mark

The_star_is_at的博客 567

用ESP32-S3打造迷你录音笔:SPIFFS存储+INMP441麦克风全流程解析

本文详细解析了如何使用ESP32-S3微控制器与INMP441数字麦克风构建迷你录音笔。内容涵盖硬件选型、I2S驱动配置、SPIFFS文件系统存储管理以及WAV格式封装等全流程,重点探讨了在资源受限的嵌入式设备上实现高质量语音采集与存储的优化方案和实战技巧。

qq_27496129的博客 1366

Vensim系统动力学建模实战:从理论到仿真优化【案例详解】

本文详细介绍了Vensim在系统动力学建模中的实战应用,从基础理论到仿真优化全面解析。通过人口增长、供应链库存优化等典型案例,展示如何利用Vensim构建动态模型并进行参数优化,帮助读者掌握系统动力学建模的核心技术与实践技巧。

weixin_29231725的博客 477

POJ3009Curling 2.0解题报告

分类:DFS,迷宫 作者:ACShiryu 时间:2011-7-23 地址:http://www.cnblogs.com/ACShiryu/archive/2011/07/23/2114718.html Curling 2.0 Time Limit:1000MS Memory Limit:65536K Total Submissions:5417...

weixin_30646315的博客 127

五子棋AI算法第一篇-我对谷歌Alphago的看法

最近Google宣布他们的围棋AI以5:0的战绩打败欧洲围棋三冠王。我一直对人工智能比较感兴趣,正好趁年前空闲的几天用JS写了一个五子棋的AI。其实很久以前就用自创的算法写过一个JAVA版的五子棋AI,不过棋力很不理想。这次用的是JS写的,所以无论任何平台上只要能打开网页的都可以玩。google爆出这个新闻之后,很多人觉得这是不是意味着电脑智商已经在人类之上了,围棋已经没有意义了之类的。甚至觉得这是

言川的博客 2万+

POJ-3009 Curling 2.0 解题报告(搜索) 冰壶游戏

C - Curling 2.0 Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u http://openoj.awaysoft.com:8080/judge/problem/viewProblem.action?id=28625    Description On Plan

潘卓夫 1171

一篇NS SAR ADC的学习记录

一篇NS SAR ADC的学习记录 内容包含: OverSampling Noise Shaping Dynamic Amplifier DAC with Redundancy 最近看了些有意思的SAR ADC结构,但是因为确实对模拟这个领域不太熟,导致了一系列的级联查找,最终达到了一个大概能懂的状态,为了理清思路,顺便别让看了这么些天的东西浪费了,还是计划写篇文章。 ps:由于不是一篇特别正紧的报告,参考文献就写的比较随便,且我还是个做数字的 A 13.5-ENOB, 107-μW Noise-Sha

weixin_45669724的博客 8711

USRP B210 运行gnuradio时 FPGA固件版本冲突错误解决方法

事情起源于昨天拿到USRP后开始调试,结果整了一个下午都没解决这个问题。 昨天晚上自己思考了一下,觉得还是版本问题。 首先,uhd_find_devices和uhd_usrp_probe均可以正常运行,没有报错,固件正常加载,序列号也可看到。 teray@teray-X550JK:~$ uhd_find_devices [INFO] [UHD] linux; GNU C++ version 7.5...

斯哈研究所 4243

POJ - 3009 Curling 2.0解题报告(dfs)

题目大意:大概就是给你一个图,然后图上有不能到的点(墙),然后你就在起点扔一个球,球只能砸到墙才能停止,但是砸到墙上之后,这个墙就没了,你最多可以砸10次,扔出界就算输,问你在一通乱砸之后,能不能把这个球从起点扔到终点。 注意,要是该点紧挨着就是一个墙,那就不能往这个墙的方向上扔。

薛崇祥的博客 648

科大讯飞(1): 环形6麦语音唤醒—驱动板上的接口

介绍环形麦阵列驱动板上的接口,及其疑问

bing_feilong的博客 1175

POJ-3009 Curling 2.0

POJ-3009 Curling 2.0 题目链接:POJ-3009 题目大意:打冰壶 你可以使冰壶向一个前面一格不为空的方向移动 冰壶遇到障碍会在障碍之前的位置停下来 并且将那个障碍击碎为空格 问你能不能到达给定的终点 能到达的话需要几步 解题思路:dfs即可 主要是注意每次dfs之前需要处理到一行的最末端 即走一行空格 另外注意10步之后默认为不能到达记得返回 这题一开始做麻烦了整整做了一下...

鱼头的水题之路 296

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

张三玩冰壶:C++用DFS深度优先搜索解POJ3009 Curling 2.0问题

POJ_3009_Curling 2.0 就不放英文题目了,去POJ搜题号就可以看到 简单理解一下题目: 张三去玩一种新出的冰壶项目,在一个棋盘一样的冰面上,他站在其中一格S上,从S点出发,有一些棋盘格有障碍物,他可以沿着上左下右四个方向运动,但是只有碰到障碍物才能停下来,而且碰到障碍物会停在运动方向上障碍物前面那个格子上,障碍物会消失,一个方向算一步,如果步数超过10或者不小心出界都算失败,问张三最短走几步能到终点G。 看一下输入: 一次性输入好几组数据,每一组开头是棋盘的横向距离和纵向距离(非常无奈我在

只想AC的博客 980

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

poj 3009 Curling 2.0

poj 3009 Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21445 Accepted: 8742 Description On Planet MM-21, after their Olympic games this ye

代码屋 224

poj 3009 ( Curling 2.0 深搜 搜直线)

题目链接:http://poj.org/problem?id=3009                                                                                                                                  Curling 2.0 Time Limi

T_T 2752

Curling 2.0 - POJ 3009

题目描述在MM-21星球上,他们的奥林匹克运动会结束后,冰壶运动变得越来越受欢迎。但是规则与我们的有些不同。游戏在一个标有方形网格的冰面游戏板上进行。他们只使用一块石头。游戏的目的是以最少的步数将石头从起点带到终点。图1显示了一个游戏板的示例。一些方块可能被障碍物占据。有两个特殊的方块,即起点和终点,它们没有被障碍物占据。(这两个方块是不同的。)一旦石头开始移动,它将一直移动直到撞到障碍物。为了将石头带到终点,你可能需要通过让石头撞到障碍物来停止石头,然后再次投掷。

weixin_73964795的博客 1158

POJ: 3009 Curling 2.0

一看是dfs就直接写了,想着这个深搜限制条件比较多而且一次可以“深入好几层”(就是走很多步),所以觉得用数组模拟四个方向不好写,就一个个枚举了,写了一会儿发现其实是可以的,就这样,一个个方向的写把代码写的很长…… 教训啊!一个个写的时候还很容易出错,改了近十分钟错才发现了一个大于号的错误…… 不过最终1a了,也算是改过错了吧。 /* POJ: 3009 Curling 2.0 */ #inc

stormdpzh的专栏 757

POJ 3009 Curling 2.0

Curling 2.0 Time Limit:1000MS Memory Limit:65536K Total Submissions:30740 Accepted:12179 Description On Planet MM-21, after their Olympic games this year, curling is getting ...

Heaper的博客 305
上一篇: POJ-3083 Children of the Candy Corn 解题报告
下一篇: POJ-1321 棋盘问题 解题报告
angle555945
博客等级 码龄15年 66粉丝 74原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值