当前位置:网站首页>SWUST oj668: the thief ran away
SWUST oj668: the thief ran away
2022-06-11 10:48:00 【Studying hard】
Title Description
Recently, the thieves in the East Sixth dormitory building are very smart , They can always find a way to escape after stealing , To catch them , We need to know their escape route , Please help find out their escape route ( To simplify the problem , We guarantee that there is at most one escape route , And the starting point is ( 0 , 0 ), End ( 4 , 4) by , You can't run away with a slash , If someone intercepts at the end , Also for the escape failure ).
Input
One 5*5 matrix , Space off 0 Represents a walkable path ,1 Indicates an obstacle , The starting point of escape is the upper left , The end point is lower rightOutput
Escape route , See output example ( Please note that x,y Axis direction ) If there is no way to escape , The output : "No Way!"( No colons or quotes )The sample input
0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0Sample output
(0,0) (0,1) (0,2) (0,3) (0,4) (1,4) (2,4) (3,4) (4,4)#include<stdio.h> #include<string.h> #define INF 0x3f3f3f3f #define MAX(x,y) (x>y?x:y) #define MIN(x,y) (x>y?y:x) #define M 10 int a[M][M]; int vis[M][M]; int dir[][2] = { {0,1},{1,0},{0,-1},{-1,0} }; int c[M][2]; int flag = 1; void dfs(int x, int y, int step) { if (x == 4 && y == 4) { for (int i = 0; i < step; i++) { printf("(%d,%d)\n", c[i][1], c[i][0]); } flag = 0; return; } for (int i = 0; i < 4; i++) { int xa = x + dir[i][0]; int ya = y + dir[i][1]; if (xa >= 0 && xa <= 4 && ya >= 0 && ya <= 4 && vis[xa][ya] == 0 && a[xa][ya] != 1) { vis[xa][ya] = 1; c[step][0] = xa; c[step][1] = ya; dfs(xa, ya, step + 1); c[step][0] = 0; c[step][1] = 0; vis[xa][ya] = 0; } } } int main() { int i, j; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { scanf("%d", &a[i][j]); } } vis[0][0] = 1; c[0][0] = 0; c[0][1] = 0; dfs(0, 0, 1); if (flag == 1) { printf("No Way!\n"); } return 0; }
边栏推荐
- &lt; Pytorch series 4 & gt;: Constructing neural network model
- [MySQL] use of stored procedures
- Hardware Description Language HDL
- MySQL (IX)
- Rxjs Observable.pipe 传入多个 operators 的执行逻辑分析
- 【CV基础】颜色:RGB/HSV/Lab
- Mxnet construction and implementation of alexnet model (comparison with lenet)
- Source code of digital collection app system
- 安装MySQL ,出现由于找不到 MSVCR120.dll,无法继续执行代码解决方法”
- 恋爱时将房屋一半产权登记在女方名下,分手后想要回
猜你喜欢

金仓数据KingbaseES 批量创建数据库对象

Dimension types for different CV tasks

MySQL基础篇常用约束总结上篇

Using hystrix to implement fault-tolerant processing of microservices

MySQL下载安装使用-完整详细步骤

金仓数据库KingbaseES中的sys_checksums坏块检测功能

Leetcode 1995. Statistics special quads (brute force enumeration)
![FPGA infrastructure [reference ug998]](/img/68/7eee191c52029dc140168bdb64b947.png)
FPGA infrastructure [reference ug998]

Summary of common constraints in MySQL foundation part I

Pyramidtnt: TNT with characteristic pyramid structure
随机推荐
Rxjs Observable.pipe 传入多个 operators 的执行逻辑分析
在线文件不落地转base64
Batch add noise to data and generate new named annotation files
Wechat cloud development al short video one click face changing applet source code
Circuit board made of real gold -- golden finger
链接器和链接器选项、运行时库和运行时库设置、配置设置、生成过程和方法
MySQL下载安装使用-完整详细步骤
C language campus tour guide consultation system
硬件描述语言HDL
Some understanding of inductive bias
基于位置服务(LBS)的SSM的框架实现的兴趣社交软件平台设计与实现
Using hystrix to implement fault-tolerant processing of microservices
jszip 获取上传的zip包中的指定文件的file
网上开户是安全的吗?普通人可以开吗?
安装MySQL ,出现由于找不到 MSVCR120.dll,无法继续执行代码解决方法”
Use of kingbasees UDP monitoring tool for gold warehouse database
使用 Hystrix 实现微服务的容错处理
Fix the problem that uicollectionview does not reach the bottom security zone
5.读取指定路径名-dirname
NFT 2.0: 下一代的NFT将是精简且值得信赖的NFT