POJ3009 Curling 2.0 (dfs入门题)

本文介绍了一款基于网格的冰壶游戏,玩家需通过最少的步骤将冰壶从起点移动到终点。游戏遵循特定规则,如冰壶只能沿水平或垂直方向移动,并在撞击障碍物后停止并移除障碍。文章提供了使用深度优先搜索(DFS)解决该问题的代码示例。
Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

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


这道题大意是一个在一个w*h的场地放一个冰壶(数字2),冰壶每次可以向一个方向滑,撞到冰(数字1)才能停下,且此时此冰破碎变成空地(数字0)。输出冰壶经过终点(数字3)最少要多少次(无法在10次内完成输出-1)。注意冰壶滑出界直接失败。

虽说是求最短次数但由于地图一直在变,还是用dfs比较好(由于最多允许滑10次所以不会超时),另外方向与行列也是经常弄混。。。反正这题建议和我一样练习dfs的新人可以做一做。

本人代码思路是提前预判停下的时机,在停下后判断前面遇到的是1,是3,亦或是地图边界,代码如下:

#include <iostream>
using namespace std;
#define N 10
int Map[22][22],Min;
int m,n;                                                            ///m横n竖
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

int in(int x,int y){
    return x>=0&&y>=0&&x<m&&y<n;
}

void dfs(int x,int y,int cnt){
    if(cnt>=Min||cnt>N)return;
    int cx,cy,tx,ty;
    for(int i=0;i<4;i++){
        cx=dir[i][1];                                           ///选择一个方向
        cy=dir[i][0];
        tx=x;
        ty=y;
        if(!in(tx+cx,ty+cy)||Map[ty+cy][tx+cx]==1)                  ///无法移动
            continue;
        while(in(tx+cx,ty+cy)&&Map[ty+cy][tx+cx]==0){               ///移动
            tx+=cx;
            ty+=cy;
        }
        if(in(tx+cx,ty+cy)&&Map[ty+cy][tx+cx]==3){                  ///找到了终点
            Min=cnt;
            return;
        }
        if(in(tx+cx,ty+cy)&&Map[ty+cy][tx+cx]==1){                  ///碰到了墙壁
            Map[ty+cy][tx+cx]=0;
            dfs(tx,ty,cnt+1);
            Map[ty+cy][tx+cx]=1;
        }
        else ;                                                 ///碰到了地图边界
    }
}

int main(){
    int i,j,x,y;
    while(cin>>m>>n&&m+n){
        Min=11;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                cin>>Map[i][j];
                if(Map[i][j]==2)Map[y=i][x=j]=0;
            }
        }
        dfs(x,y,1);
        if(Min==11)cout<<-1<<endl;
        else cout<<Min<<endl;
    }
}



安全帽与口罩检测数据集 一、基础信息 数据集名称:安全帽与口罩检测数据集 图片数量: - 训练集:1690张图片 - 验证集:212张图片 - 测试集:211张图片 - 总计:2113张实际场景图片 分类类别: - HelmetHelmet:戴安全帽的人员,用于安全防护场景的检测。 - personwithmask:戴口罩的人员,适用于公共卫生监测。 - personwith_outmask:未戴口罩的人员,用于识别未遵守口罩佩戴规定的情况。 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 数据格式:JPEG/PNG图片,来源于实际监控和场景采集,细节清晰。 二、适用场景 工业安全监控系统开发: 数据集支持目标检测任务,帮助构建自动检测人员是否佩戴安全帽的AI模型,适用于建筑工地、工厂等环境,提升安全管理效率。 公共卫生管理应用: 集成至公共场所监控系统,实时监测口罩佩戴情况,为疫情防控提供自动化支持,辅助合规检查。 智能安防与合规检查: 用于企业和机构的自动化安全审计,减少人工干预,提高检查准确性和响应速度。 学术研究与AI创新: 支持计算机视觉目标检测领域的研究,适用于安全与健康相关的AI模型开发和论文发表。 三、数据集优势 精准标注与实用性: 每张图片均经过标注,边界框定位准确,类别定义清晰,确保模型训练的高效性和可靠性。 场景多样性与覆盖性: 包含安全帽和口罩相关类别,覆盖工业、公共场所以及多种实际环境,样本丰富,提升模型的泛化能力和适应性。 任务适配性强: 标注兼容主流深度学习框架(如YOLO),可直接用于目标检测任务,便于快速集成和部署。 实际应用价值突出: 专注于工业安全和公共健康领域,为自动化监控、合规管理以及疫情防护提供可靠数据支撑,具有较高的社会和经济价值。
内容概要:本文围绕FOC电机控制代码实现与调试技巧在计算机竞赛中的应用,系统阐述了从基础理论到多场景优化的完整技术链条。文章深入解析了磁链观测器、前馈控制、代码可移植性等关键概念,并结合FreeRTOS多任务调度、滑动窗口滤波、数据校验与热仿真等核心技巧,展示了高实时性与稳定性的电机控制系统设计方法。通过服务机器人、工业机械臂、新能源赛车等典型应用场景,论证了FOC在复杂系统协同中的关键技术价值。配套的千行级代码案例聚焦分层架构与任务同步机制,强化工程实践能力。最后展望数字孪生、低代码平台与边缘AI等未来趋势,体现技术前瞻性。; 适合人群:具备嵌入式开发基础、熟悉C语言与实时操作系统(如FreeRTOS)的高校学生或参赛开发者,尤其适合参与智能车、机器人等综合性竞赛的研发人员(经验1-3年为佳)。; 使用场景及目标:① 掌握FOC在多任务环境下的实时控制实现;② 学习抗干扰滤波、无传感器控制、跨平台调试等竞赛实用技术;③ 提升复杂机电系统的问分析与优化能力; 阅读建议:此资源强调实战导向,建议结合STM32等开发平台边学边练,重点关注任务优先级设置、滤波算法性能权衡与观测器稳定性优化,并利用Tracealyzer等工具进行可视化调试,深入理解代码与系统动态行为的关系。
【场景削减】拉丁超立方抽样方法场景削减(Matlab代码实现)内容概要:本文介绍了基于拉丁超立方抽样(Latin Hypercube Sampling, LHS)方法的场景削减技术,并提供了相应的Matlab代码实现。该方法主要用于处理不确定性问,特别是在电力系统、可再生能源等领域中,通过对大量可能场景进行高效抽样并削减冗余场景,从而降低计算复杂度,提高优化调度等分析工作的效率。文中强调了拉丁超立方抽样在保持样本代表性的同时提升抽样精度的优势,并结合实际科研背景阐述了其应用场景与价值。此外,文档还附带多个相关科研方向的Matlab仿真案例和资源下载链接,涵盖风电、光伏、电动汽车、微电网优化等多个领域,突出其实用性和可复现性。; 适合人群:具备一定Matlab编程基础,从事电力系统、可再生能源、优化调度等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于含高比例可再生能源的电力系统不确定性建模;②用于风电、光伏出力等随机变量的场景生成与削减;③支撑优化调度、风险评估、低碳运行等研究中的数据预处理环节;④帮助科研人员快速实现LHS抽样与场景削减算法,提升仿真效率与模型准确性。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,理解拉丁超立方抽样的原理与实现步骤,并参考附带的其他科研案例拓展应用思路;同时注意区分场景生成与场景削减两个阶段,确保在实际项目中正确应用该方法。
道路坑洞目标检测数据集 一、基础信息 • 数据集名称:道路坑洞目标检测数据集 • 图片数量: 训练集:708张图片 验证集:158张图片 总计:866张图片 • 训练集:708张图片 • 验证集:158张图片 • 总计:866张图片 • 分类类别: CirEllPothole CrackPothole IrrPothole • CirEllPothole • CrackPothole • IrrPothole • 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 • 数据格式:图片为常见格式(如JPEG/PNG),来源于相关数据采集。 二、适用场景 • 智能交通监控系统开发:用于自动检测道路坑洞,实现实时预警和维护响应,提升道路安全。 • 自动驾驶与辅助驾驶系统:帮助车辆识别道路缺陷,避免潜在事故,增强行驶稳定性。 • 城市基础设施管理:用于道路状况评估和定期检查,优化维护资源分配和规划。 • 学术研究与创新:支持计算机视觉在公共安全和交通领域的应用,推动算法优化和模型开发。 三、数据集优势 • 精准标注与类别覆盖:标注高质量,包含三种常见坑洞类型(CirEllPothole、CrackPothole、IrrPothole),覆盖不同形态道路缺陷。 • 数据多样性:数据集涵盖多种场景,提升模型在复杂环境下的泛化能力和鲁棒性。 • 任务适配性强:标注兼容主流深度学习框架(如YOLO),可直接用于目标检测任务,支持快速模型迭代。 • 实际应用价值:专注于道路安全与维护,为智能交通和城市管理提供可靠数据支撑,促进效率提升。
废物分类实例分割数据集 一、基础信息 数据集名称:废物分类实例分割数据集 图片数量: - 训练集:2,658张图片 - 验证集:316张图片 - 测试集:105张图片 - 总计:2,974张图片(训练集 + 验证集) 分类类别: - 电子产品(electronics) - 玻璃瓶(gbottle) - 口罩(mask) - 金属(metal) - 塑料袋(pbag) - 塑料瓶(pbottle) - 废物(waste) 标注格式:YOLO格式,包含多边形点坐标,适用于实例分割任务。 数据格式:JPEG图片,来源于实际场景,涵盖多种废物物品。 二、适用场景 智能废物分类系统开发: 数据集支持实例分割任务,帮助构建能够自动识别和分割废物物品的AI模型,辅助垃圾分类和回收管理。 环境监测与环保应用: 集成至智能垃圾桶或监控系统,提供实时废物识别功能,促进环保和资源回收。 学术研究与技术创新: 支持计算机视觉与环境保护交叉领域的研究,助力开发高效的废物处理AI解决方案。 教育与培训: 数据集可用于高校或培训机构,作为学习实例分割技术和AI在环境应用中实践的重要资源。 三、数据集优势 类别多样性与覆盖广: 包含7个常见废物和可回收物品类别,如电子产品、玻璃瓶、口罩、金属、塑料袋、塑料瓶和废物,涵盖日常生活中的多种物品,提升模型的泛化能力。 精准标注与高质量: 每张图片均使用YOLO格式进行多边形点标注,确保分割边界精确,适用于实例分割任务。 任务导向性强: 标注兼容主流深度学习框架,可直接用于实例分割模型的训练和评估。 实用价值突出: 专注于废物分类和回收管理,为智能环保系统提供关键数据支撑,推动可持续发展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值