ZOJ 2110 Tempter of the Bone (DFS+减枝)

YOLOv11改进 | 主干/Backbone篇 | 华为最新目标检测网络VanillaNet(适配yolov11的N、S、M、L、X) 本文给大家来的改进机制是华为最新VanillaNet网络VanillaNet是一种注重极简主义和效率的神经网络架构。它的设计简单,层数较少,避免了像深度架构和自注意力这样的复杂操作(需要注意的是该网络结构的通道数会被放大,GFLOPs的量会很高)。我将其替换整个YOLOv10的Backbone,在一些大目标和小目标检测上均有涨点,效果比上一篇RepViT的效果要好。 阅读详情

Tempter of the Bone

Time Limit: 2 Seconds Memory Limit: 65536 KB

The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.

The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.


Input

The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:

'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.

The input is terminated with three 0's. This test case is not to be processed.


Output

For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.


Sample Input

4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0


Sample Output


NO
YES


思路:直接深搜所有可以从S到D的路径,如果有答案就马上返回。其中需要减枝,否则会超时。

             t-tt-abs(x-ox)+abs(y-oy)<0 不行仍然超时

           当t-tt-abs(x-ox)+abs(y-oy)<0或者是奇数都不行这样,680ms能过

           再加上当n*m-x的数目<=t 160MS能过

#include<iostream>
#include<cstring>
using namespace std;
const int mm=11;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
char grap[mm][mm];
bool vis[mm][mm];
int m,n,t,ox,oy;
int abs(int x)
{
  return x>0?x:-x;
}
bool dfs(int x,int y,int tt)
{ int tx,ty;
  if(grap[x][y]=='D'&&tt==t)return true;
  int tmp=t-tt-abs(x-ox)-abs(y-oy);
  if(tmp<0||tmp%2==1)return false;
  for(int i=0;i<4;i++)
  {
    tx=x+dx[i];ty=y+dy[i];
    if(tx>=0&&tx<m&&ty>=0&&ty<n&&!vis[tx][ty]&&grap[tx][ty]!='X')
    { vis[tx][ty]=1;
      if(dfs(tx,ty,tt+1))return true;
      vis[tx][ty]=0;
    }
  }
  return false;
}
int main()
{
  while(cin>>m>>n>>t)
  { int x,y;
    if(m==0&&n==0&&t==0)break;
    memset(vis,0,sizeof(vis));
    int w=0;
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
    {
      cin>>grap[i][j];
      if(grap[i][j]=='S')
        x=i,y=j;
      if(grap[i][j]=='D')
        ox=i,oy=j;
      if(grap[i][j]=='X')
        w++;
    }
    if(n*m-w<=t){cout<<"NO\n";continue;}
    vis[x][y]=1;
    if(dfs(x,y,0))
      cout<<"YES\n";
    else cout<<"NO\n";
  }
}




华为OD机试双机位C卷:挑选宝石 (C/C++/Python/JAVA/JS/GO) 华为OD机试双机位C卷 挑选宝石,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。华为OD机试-挑选宝石,华为OD机考-挑选宝石。 阅读详情

相关推荐

TI C2000 , .cmd文件,.TI.ramfunc,将程序分配为在RAM中运行/Flash运行的配置方法和原理讲解,(如28375S ,280049,28335等等芯片)

1 基础知识讲解 1.1 在RAM中运行还是在flash中运行指的是什么? 1.1.1 背景:程序编译完之后生成的.bin文件,.bin文件中包含代码段,代码段中全是汇编指令,而汇编指令中包含多个函数,各函数头的地址不同,如存在A函数和B函数,假设RAM地址区间是0x0000-0x8000,flash的地址区间是0xA000-0xF000,A函数要调用B函数,则A函数调用B函数的那段汇编指令中包含的是B函数头的存储地址,A函数和B函数都在flash中有存储 1.1.2 情况1:B函数是配置为在RAM中运行,

weixin_43776284的博客 8065

zoj 2110 Tempter of the Bone

<br />DFS。<br /> <br />之前一直TLE了,死活不会优化 = =。。就搜了下。<br /> <br />那个用距离判断的我也加了,还是TLE了 = =。。学到个这个,这一句很神奇。。。<br /> <br /> <br />if( d % 2 != (Time-t) % 2 )<br />return ;<br /> <br /> <br />刚才自己手动模拟了下,理解了。d是当前点与目标点的坐标差。Time-t即从当前点到达目标点需要走多少步。<br /> <br />这两个值的奇偶性

小媛在努力~ 1876

Java 简易版 UDP 多人聊天室

【代码】Java 简易版 UDP 多人聊天室。

nmy15570188135的博客 1187

ZOJ 2110 Tempter of the Bone

题意:在迷宫里,'X'表示墙,'S'表示起点,'D'表示终点,'.' 表示路,在起点处有一条狗,每秒可以移动一格,多组数据,每组第一行有三个数据,分别为迷宫的宽度和高度,与时间,判断这条狗是否能走出迷宫。 链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1110 思路:因为迷宫范围比较小,可以用DFS搜索,因为要时

luminous11的专栏 527

EtherCAT-7 从站代码移植-SPI

STM32F103 + AX58100,从站代码移植。

tianya_xuan的博客 3567

GoPro官方API实战:从蓝牙配对到Wi-Fi流媒体,构建跨平台控制应用

本文详细解析了GoPro官方API的开发实践,涵盖蓝牙配对、Wi-Fi流媒体控制等关键技术。通过实战案例,指导开发者如何构建跨平台控制应用,解决设备发现、指令解析、视频流传输等核心问题,并分享Android平台迁移经验与常见问题排查方法。

weixin_30727835的博客 397

Zoj 2110 Tempter of the Bone

题目描述: 一只小狗在一个古老的迷宫里找到一根骨头,当它叼起骨头时,迷宫开始颤抖,它感觉到地 面开始下沉。它才明白骨头是一个陷阱,它拼命地试着逃出迷宫。 迷宫是一个N×M 大小的长方形,迷宫有一个门。刚开始门是关着的,并且这个门会在第T 秒 钟开启,门只会开启很短的时间(少于一秒),因此小狗必须恰好在第T 秒达到门的位置。每秒钟, 它可以向上、下、左或右移动一步到相邻的方格中。但一旦它移

Paradiser 989

手把手教你使用transciver-ip核的配置

手把手教你使用transciver-ip核的配置

u012938458的博客 5411

zoj2110-Tempter of the Bone

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1110 题目属于dfs的基础题,但是需要剪枝,不过还是卡了很久,这也看出了自己在这方面的漏洞,而且没有注意细节,例如YES我习惯性的写成了Yes了,其次,第一次剪枝时,忘了加continue,找了好久都没找到错误。 #include #include const int

bo-jwolf的专栏 1143

File does not exist: /user/anonymous/.staging/job_1628851608378_6064/报错问题解决

user/admin/.staging/job_1571397171638_0001/job_1571397171638_0001_1.jhist 所以为什么没有下发,这里面jhist,只是被引发的错误,它还不是根本的错误。看到上面错误,我们就可以判断,这是网络问题,然而网络无非是ip地址,防火墙,端口,hosts等。我们正常的hosts是这样的。在回头复盘想想,我们找不到jhist,跟我们的网络问题二者是很难找到关联的,所以大家在遇到问题的时候,一定多排查和思考,而不是看到一个错误,就以为是它的问题。

石榴姐yyds 2170

vxWorks下dosFs文件系统的创建

文件系统,是指操作系统根据目录和文件的组织形式在磁盘设备上应用的一种设备驱动,不同的文件系统对目录和文件有不同的限制(如目录名限制,文件大小限制等)。VxWorks支持多种文件系统,比较重要的有:1、dosFs:适用于块存取设备(比如硬盘、软盘),和MS-DOS文件系统兼容;2、rawFs:提供了一种简单的原始文件系统。该文件系统将整个硬盘当作一个单独的大文件;3、cdromFs:允许系统从按照I

技术联盟 1万+

ZOJ-2110 Tempter of the Bone( 搜索,奇偶性剪枝)

/*2110Tempter of the Bone--------------------------------------------------------------------------------Time Limit: 1 Second      Memory Limit: 32768 KB ----------------------------------------

轻疯 清风 2894

组合导航 | RTK、IMU与激光雷达组合导航算法:原理、实现与验证

当激光雷达噪声增加至0.1m时,系统位置RMSE仅上升18%,验证了滤波算法的鲁棒性[110]:融合方案在RTK信号丢失30秒后,位置误差仍控制在1.5m内,显著优于IMU单独导航[28]:ESKF框架能有效建模传感器误差特性,状态向量需包含外参与时间偏移等关键参数。:传感器标定精度直接影响系统性能,建议每3个月进行一次重新标定。:IMU预积分与特征匹配是系统实时性的关键瓶颈,需重点优化。:维持10秒窗口内的关键帧,平衡精度与实时性[132]:特征匹配占总耗时的65%,可通过。

尘世冰封的专栏 943

zoj 2110 Tempter of the Bone (dfs)

Tempter of the BoneTime Limit:2 Seconds Memory Limit:65536 KB The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shak...

anque1234的博客 157

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

G - Tempter of the Bone

G - Tempter of the Bone Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 2110 Descript

ACM_hades的梦想之路 821

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

ZOJ2110Tempter of the Bone(DFS模板题,迷宫问题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2110 题意: 一只小狗在一个古老的迷宫里找到一根骨头,当它叼起骨头时,迷宫开始颤抖,它感觉到地 面开始下沉。它才明白骨头是一个陷阱,它拼命地试着逃出迷宫。  迷宫是一个 N×M大小的长方形,迷宫有一个门。刚开始门是关着的,并且这个门会在第 T秒 钟开启,门只

Keaper的博客 629

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ZOJ-Tempter of the Bone(dfs+剪枝)

Tempter of the Bone The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He re...

1255

HDU1010 ZOJ2110 Tempter of the Bone【DFS】

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 153873 Accepted Submission(s): 40981 Problem Description The doggie foun...

海岛Blog 579

zoj(2110)Tempter of the Bone(DFS+奇偶剪枝)

剪枝很重要,可走的格数小于时间则减去,然后就是奇偶性剪枝可以把map看成这样: 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 从为 0 的格子走一步,必然走向为 1 的格子 从为 1 的格子走一步,必然走向为 0 的格子 即: 0 ->1或1->0 必然是奇数步 0->0 走1->1 必然是偶数步...

weixin_30889885的博客 137

ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)

题意  一只狗要逃离迷宫  可以往上下左右4个方向走  每走一步耗时1s  每个格子只能走一次且迷宫的门只在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径  或者走完所有可能路径都不满足 注意剪枝  当前位置为(r,c)  终点为(ex,ey) 剩下的时间为lt  当前点到终点的直接距离为  d=(ex-r)+(ey-c)   若多走的时间rt=lt-d

Deng's site \# 983

zoj2110 - Tempter of the Bone (DFS + 奇偶性剪枝)

Tempter of the Bone Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                             The doggie found a bone in an ancient maze, which fascinated h

ITCTO-疯男的优快云博客 540

Tempter of the Bone解析(回溯算法)hdu1010 zoj2110

Tempter of the Bone<br /><br />Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a

qq943574281的专栏 1438

HDU 1010 && ZOJ 2110--Tempter of the Bone【DFS && 奇偶剪枝】

Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 89408    Accepted Submission(s): 24316 Problem Description The dogg

_阿阿阿阿欢 643

zoj2110Tempter of the Bone

#include #include #include #include using namespace std; int d[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0} }; int N, M, T; char map1[10][10]; int flag[10][10]; int sx, sy, ex, ey; bool res;///repre

Achiberx 1130

zoj2110 Tempter of the Bone 搜索dfs

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1110 题目大意:

basement_boy 536
上一篇: poj 1659 Frogs' Neighborhood(判断序列可图)
下一篇: ZOJ 2412 Farm Irrigation(DFS+状态压缩)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值