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而已。

避坑指南:ShardingSphere连接达梦/金仓数据库时SQL解析器的那些‘坑‘

本文深入探讨了ShardingSphere与国产数据库(如达梦、金仓)集成时遇到的SQL解析器差异问题,提供了详细的解决方案和优化策略。通过分析SQL方言差异、JDBC实现差异及解析器兼容性,帮助开发者有效避坑,提升分布式数据库架构设计的效率与稳定性。

weixin_29309475的博客 392

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

深度学习——VGG16模型详解

1、网络结构 VGG16模型很好的适用于分类和定位任务,其名称来自牛津大学几何组(Visual Geometry Group)的缩写。 根据卷积核的大小核卷积层数,VGG共有6种配置,分别为A、A-LRN、B、C、D、E,其中D和E两种是最为常用的VGG16和VGG19。 介绍结构图: conv3-64 :是指第三层卷积后维度变成64,同样地,conv3-128指的是第三层卷积后维度变成128; input(224x224 RGB image) :指的是输入图片大小为224244的彩色图像,通道为

橙子的博客 12万+

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

SPSS操作(五):主成分分析

1、将数据导入spss,并定义变量,将铁路运输业职工人数(人)、城市公共交通业职工人数(人)、邮政业职工人数(人)、电信和其他信息传输服务业职工人数(人)、客运量(万人)、接待入境旅游人数(万人次)、普通高校师生比(%)、星级住宿业营业额(亿元)分别定义为x1,x2,x3,x4,x5,x6,x7,x8 如图: 2、对数据进行标准化处理 ①选择【分析】—【描述统计】—【描述】 ②添加要标准化的变量,勾选【将标准化值另存为变量(Z)】,再点确定 ③返回原来的数据窗口就可以看见标准化后的变量了 3、SPS

My_daily_life的博客 8万+

ali140滑块

ali 140滑块采用补环境的方式进行逆向,需要的文件主要为这两个,其中collina.js是最主要的环境校验和参数加密的逻辑,这两个文件放本地进行补环境。然后挂上代理,先保证能够正常运行代码,补了些许后能够正常运行了,我们打印最主要的加密函数看看:n值就是得到:挂上代理看看鼠标事件,不管加密逻辑,关心入参即可:收集一些鼠标事件传进记录的函数。其余就是处理一些环境值,一些resetSA的逻辑就行。截图记录:

bboysteed的博客 1677

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

墨刀原型设计工具操作使用指南及实践操作

该指南通过异常场景处理、像素级参数说明、复杂交互示例,覆盖了墨刀操作的全细节,适合从新手到资深用户的进阶学习。结合 PlantUML 思维导图的层级化展示,可快速定位具体功能的操作要点与问题解决方法,真正实现 “照指南即可操作” 的实用价值。

hy行者勇哥的博客 4948

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

ptrade从零开始学习量化交易第166期【ptrade量化策略研究参考--三个因子挖掘思路】

三个因子挖掘思路

GJ57017_wx的博客 1247

10.2 全栈 CRUD 工程结构搭建:Cursor 4 步初始化 + 3 层目录规范

揭示 Cursor 工程初始化中 4 个关键动作如何将 AI 上下文感知能力从 30% 提升至 85%,包括用 pnpm create 显式声明结构契约、通过 monorepo.config.json 设定 workspace 根以支持跨包类型引用、在 shared 包中固化共享类型与协议,以及后续

weixin_42545292的博客 67

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

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

薛崇祥的博客 648

PX4从放弃到精通(五):PX4中的姿态表示方法及转换关系

文章目录机体坐标系与地理坐标系一、pandas是什么?二、使用步骤1.引入库2.读入数据总结 机体坐标系与地理坐标系 在实际应用中,加速度计的测量轴是由运动平台安装固定此器件的轴向决定的。这些坐标轴就形成了载体坐标系,定义如下: 坐标原点设在载体质心(这样可简化运动方程的推导); y轴指向载体前方,称为横滚轴,横滚角以y轴为起始旋转轴而得到,符合右手定则; x轴与y轴夹角90°,指向载体横向,称为俯仰轴,俯仰角以x轴为起始旋转轴而得到,符合右手定则; z轴与x轴、y轴构成右手笛卡儿坐标系,指向载体垂直方向

超维空间科技的博客 8113

POJ-3009 Curling 2.0

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

鱼头的水题之路 296

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

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

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

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

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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、付费专栏及课程。

余额充值