首页 技术 正文
技术 2022年11月17日
0 收藏 888 点赞 2,995 浏览 673 个字

题目描述

给出起点和终点的坐标及接下来T个时刻的风向(东南西北),每次可以选择顺风偏移1个单位或者停在原地。求到达终点的最少时间。

如果无法偏移至终点,输出“-1”。

输入输出格式

输入格式:

第一行两个正整数x1,y1,表示小明所在位置。

第二行两个正整数x2,y2,表示小明想去的位置。

第三行一个整数T,表示T个时刻。

第四至第N+3行,每行一个字符,表示风向,即东南西北的英文单词的首字母。

输出格式:

最少走多少步。

比较简单的搜索。

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 0x3f3f3f3f;
int x1, y1, x2, y2,k;
char str[];
int dfs(int x, int y, int st){
if (x == x2&&y == y2)return ;
if (st+ > k)return maxn;
int a = x, b = y;
if (str[st] == 'E'){ ++b; }
else if (str[st] == 'S'){ --a; }
else if (str[st] == 'W'){ --b; }
else if (str[st] == 'N'){ ++a; }
return min(dfs(x, y, st+), dfs(a, b, st + ) + );
}int main(){
cin >> x1 >> y1;
cin >> x2 >> y2;
cin >> k;
for (int i = ; i <= k; ++i)
cin >> str[i];
int ans=dfs(x1, y1, );
if (ans == maxn)cout << - << endl;
else cout << ans << endl;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896