POJ 3009 - Curling 2.0(深搜)

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

Curling 2.0
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8930 Accepted: 3762

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


============================

就是一种小游戏……

从2开始;

只能横竖方向走;

如果石头是静止的时候可以任意选择一个旁边没有障碍的方向扔出去;

除非碰到障碍物否则会一直运动下去;

如果运动的时候碰到障碍物,停止运动,障碍物消失;

如果运动到区域外就失败了;

如果达到终点(3)就成功了;

运动十次以上也算失败。

具体的可以结合题中的图来看


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,startx,starty,endx,endy,minans;
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int map[22][22];

bool check(int x,int y)
{
    if(x>=1&&x<=n&&y>=1&&y<=m) return 1;
    return 0;
}

void dfs(int x,int y,int ans)
{
    if(ans>10) return;//运动次数大于10
    int dx,dy;
    for(int i=0;i<4;i++)
    {
        //cout<<"i="<<i<<endl;
        dx=x+dir[i][0];
        dy=y+dir[i][1];
        if(dx==endx&&dy==endy)
        {
            if(ans<minans) minans=ans;
            return;
        }
        if( map[dx][dy]==1 || (!check(dx,dy)) )//不能朝这个方向前进
        {
            //cout<<"aaaa"<<endl;
            continue;
        }
        while(map[dx][dy]!=1)//如果没有障碍则一直前进
        {
            dx+=dir[i][0];
            dy+=dir[i][1];
            if(dx==endx&&dy==endy)
            {
                if(ans<minans) minans=ans;
                //cout<<"cccc"<<endl;
                return;
            }
            if(!check(dx,dy))
            {
                //cout<<"dddd"<<endl;
                break;
            }
        }
        if(!check(dx,dy)) continue;
        map[dx][dy]=0;//障碍物消失
        dfs(dx-dir[i][0],dy-dir[i][1],ans+1);//注意要退回来搜索
        map[dx][dy]=1;//回溯
    }
}

int main()
{
    while(~scanf("%d%d",&m,&n))
    {
        if(m==0&&n==0) break;
        minans=1e9;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                scanf("%d",&map[i][j]);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(map[i][j]==2)
                {
                    startx=i;starty=j;
                }
                if(map[i][j]==3)
                {
                    endx=i;endy=j;
                }
            }
        }
        dfs(startx,starty,1);
        if(minans!=1e9) printf("%d\n",minans);
        else printf("-1\n");
    }
    return 0;
}


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

相关推荐

Android11 关于三方应用获取su权限

SELinux,全称Security-Enhanced Linux,是一种基于Linux内核的安全机制。它通过强制访问控制(MAC)来增强Linux系统的安全性,如果不禁用SELinux,完成下面的修改可能会导致设备进入Recovery界面!adb shell getenforce 为Permissive(宽容模式),查看报错日志,发现是客户apk想使用su命令提权,但是没有权限!对于保护系统资源和防止未经授权访问非常有帮助!系统这边做修改,让su权限下放到三方应用.客户的apk运行报错。

sinat_37429535的博客 1901

poj 3009 ( Curling 2.0 深搜 搜直线)

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

T_T 2752

第9章:Embedding、Pooling 与检索增强基础

本文介绍了律师事务所如何利用vLLM构建法律文档RAG系统,解决传统关键词检索在语义匹配上的不足。主要内容包括: 项目背景:传统Elasticsearch检索在法律术语上的低准确率问题,及多模型维护的复杂性; 技术方案:采用vLLM统一支持生成和向量化能力,通过语义向量检索提升相关性; 关键实现: 用vLLM的Embedding端点处理文档向量化 构建包含离线索引和在线检索的完整RAG流程 采用余弦相似度进行语义匹配 实践建议:切片大小选择、向量归一化处理、不同场景下的数据库选型等。

davidwang456的专栏 60

poj 3009 Curling 2.0 深搜

http://poj.org/problem?id=3009 题意:一个小球在一个格子里滑行,当你给它一个力时,他会一直滑,直到前方碰到一个雪球停止,这时前方的雪球会消失,你继续给该小球任意一个方向的力。。。问至少需要几步才能到达到终点。 分析: 一般在求 最短路 时会用到 广搜,但是 本题 在搜索时, 每走一步, 现场...

aidibi1469的博客 294

基于ZYNQ PL的AD7606数据采集与FFT实时频谱分析:从硬件到创新实现

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kKnmpgJm-1750295287594)(https://example.com/fft_plot.png)]本文涉及代码已在Xilinx ZCU102开发板与AD7606评估板上验证通过,采样率支持200KSPS@8通道,FFT计算延迟<1ms。传统MCU+DSP方案难以兼顾速度与功耗,而ZYNQ的PL+PS架构为这一问题提供了完美解决方案。本文实现的ZYNQ PL方案突破了传统处理器的性能瓶颈,通过。

QQ_778132974的博客 339

路径规划 | 图解Informed RRT*算法(附ROS C++/Python/Matlab仿真)

Informed RRT*算法针对RRT*算法进行了采样优化,用椭圆采样代替全局均匀采样,避免了RRT*算法搜索树上产生过多冗余分支的缺陷。本文图解Informed RRT*原理,并提供ROS C++/Python/Matlab三种实现加深理解

FRIGIDWINTER的博客 7484

POJ3009 Curling 2.0 DFS 深搜

题目大意:地图上“0”代表空白可滑动区域,“1”代表阻碍物,“2”代表起点,“3”代表终点。冰壶从起点开始可以朝上下左右四个方向滑动,若没有遇到阻碍物或者没有到达终点则不会停止,直到滑出地图。若遇到阻碍物后冰壶会停止在阻碍物前一格,被碰撞的阻碍物会消失。需要注意的是,若在冰壶旁边有障碍物,则不可朝障碍物一侧滑动。求冰壶到达终点的最短滑动次数。若10次滑动不能到达终点,则视为不能到达,输出-1。

jyxjyx27的专栏 528

YOLOv11改进 | Conv篇 | 2024最新轻量化自适应提取模块LAE助力边缘设备部署计算(附代码 + 修改教程 + 运行教程)

本文给大家带来的一个改进机制是最新由LSM-YOLO提出的轻量化自适应特征提取(Lightweight Adaptive Extraction, LAE)模块,其是LSM-YOLO模型中的关键模块,旨在进行多尺度特征提取,同时降低计算成本。LAE通过以下方式实现更有效的特征提取:多尺度特征提取、自适应特征提取。LAE模块可以在不增加额外参数的情况下提高了模型对ROI区域的检测性能。​欢迎大家订阅我的专栏一起学习YOLO!YOLOv11改进系列专栏——本专栏持续复习各种顶会内容——科研必备目录一、本文介绍。

Snu77的博客 4056

[Poj 3009] Curling 2.0 深搜

Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16394 Accepted: 6773DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popular. But

ATOD 560

基于 ESP32 的分布式光伏微电网智能监控系统设计与实现

设备 / 模块连接 ESP32 引脚备注I2C 总线(SDA)GPIO21所有 I2C 设备共用I2C 总线(SCL)GPIO22所有 I2C 设备共用DS18B20(单总线)GPIO18单总线通信,需外接 4.7K 上拉电阻有源蜂鸣器GPIO19低电平触发,串联 100Ω 限流电阻ESP32 供电5V/GND由 LM2596 输出 5V 供电,或直接 USB 供电(调试阶段)INA219(光伏)光伏阵列正负极接 INA219 的 VIN+/VIN-

weixin_42300449的博客 304

YOLOv11旋转目标检测详解:从原理到实战的全面指南

本文介绍了YOLOv11旋转目标检测技术的核心概念、架构设计与应用场景。传统目标检测使用水平边界框(AABB)存在背景噪声大、定位精度低等问题,而旋转边界框(OBB)通过引入角度参数显著提升了检测精度,在遥感、OCR、工业质检等领域具有独特优势。YOLOv11-OBB采用改进的多尺度检测层、CSPDarknet53骨干网络和双通道角度输出机制,在保持实时性的同时实现精确的旋转目标检测。实验表明,该方法在DOTA数据集上达到81.3%的mAP,相比传统方法提升显著,特别适合处理具有旋转特性或高宽比悬殊的目标。

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 301

POJ 3009 深搜 Curling 2.0

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

weixin_30583563的博客 76

5、数据计算与处理技巧全解析

本文深入解析了Tableau中的多种数据计算与处理技巧,涵盖LOD计算、日期与字符串处理、计数优化、数据混合限制及自定义总计等核心内容。通过实际案例和流程图,系统讲解了各技巧的应用场景、实现步骤与注意事项,并提供性能优化建议和常见问题解答,帮助用户提升数据分析效率与可视化精度。同时展望了未来数据计算技术的发展趋势,是Tableau用户进阶必备的全面指南。

peach的博客 82

POJ3009_Curling 2.0_深搜

Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19734   Accepted: 8063 Description On Planet MM-21, after their Olympic games this year, curling

弱的奋斗之旅 424

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

POJ-3009 Curling 2.0 (深搜)

Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9347   Accepted: 3950 Description On Planet MM-21, after their Olympic games this year, curling

狂飙的蜗牛 的专栏 782

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

poj3009 Curling 2.0 深搜

PS:以前看到题目这么长就没写下去了。今天做了半天,没做出来。准备看题解,打开了网站都忍住了,最后还是靠自己做出来的。算是一点进步吧。 分析:   题目的意思没明白或者理解有偏差都没办法做题。看样例3和样例4,数据差不多的,但是一个输出4,但是另外的一个却是-1。再去看题目就会发现,题目的意思是在撞碎石头之前必须走一个为值0的格子。我理解为需要加速。对样例4,答案4是这样出来的:初始...

weixin_30563319的博客 109

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

POJ 3009 Curling2.0 冰壶 深搜DFS AC代码C/C++

原题: http://poj.org/problem?id=3009 AC代码: #include<iostream> #include<algorithm> #include<cstring> #define INF 999999 using namespace std; int s[21][21],move[4][2]={-1,0,0,1,1,0,0,-1}...

cc2855816075的博客 448

POJ3009 Curling2.0(深搜)

1.w和h的顺序搞反了 2.模拟往一个方向滑的时候用不同的数字表示不同的情况(find函数) 3.深搜终止条件不能忘 4.复制粘贴相似代码要谨慎 题目就是直接四个方向搜就ok。虽然调试样例调试了很久,但是一把直接AC爽。 #include #include using namespace std; #define INF 100000 int maps[102][1

叶子心情你不懂 231

POJ 3009 Curling 2.0(深搜)

DescriptionOn 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 me

so_so_y的博客 440

【POJ3009】Curling 2.0(深搜)

题目大意: 深搜各个方向,细节见代码。

CaptainChen的博客 342

深搜+回溯 poj3009 Curling 2.0

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

fanesemyk的博客 350

POJ-3009 Curling 2.0

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

鱼头的水题之路 296

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: 18264   Accepted: 7517 Description On Planet MM-21, after their Olympic games this year, curling

qq_35562816的博客 283

Curling 2.0 - POJ 3009

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

weixin_73964795的博客 1158

POJ3009 Curling 2.0

这道题虐我一百遍 真的是难受 Curling 2.0 本来想学个直线搜索和回溯的,结果他妈的代码,疯狂搞我。 坑点: 1.输入时先列后行 2.冰壶碰撞之后石头会碎掉 3.冰壶停在石头的前一个位置 //#include<bits/stdc++.h> #include<cstdio> #include<algorithm> #include<cstring&g...

姚军 279
上一篇: POJ 1979 - Red and Black(深搜)
下一篇: CodeForces 148B - Escape
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值