298B Sail
来源:互联网 发布:结局意外的电影知乎 编辑:程序博客网 时间:2024/06/11 09:30
http://codeforces.com/problemset/problem/298/B
模拟题,开始坐标(sx,sy),终点坐标(ex,ey)。
用终点坐标减去现在坐标的绝对值表示距离远近,
若风向导致绝对值变小,则采纳此次行动。否则不予理会。
//cf 298B Sail/*模拟题,开始坐标(sx,sy),终点坐标(ex,ey)。用终点坐标减去现在坐标的绝对值表示距离远近,若风向导致绝对值变小,则采纳此次行动。否则不予理会。*/#include <iostream>#include <cstdio>using namespace std;int t,sx,sy,ex,ey;int ct;char s[100020];inline int dabs(int x){ if (x<0) return -x; return x;}int main(){ while(scanf("%d %d %d %d %d",&t,&sx,&sy,&ex,&ey)!=EOF) { ct =-1; scanf("%s",s); int nextx,nexty; for (int i = 0;i<t;i++) { switch (s[i]) { case 'E': { nextx = sx +1; nexty = sy; break; } case 'S': { nextx = sx; nexty = sy-1; break; } case 'W': { nextx = sx -1; nexty = sy; break; } case 'N': { nextx = sx; nexty = sy+1; break; } default:break; } if (dabs(ex-nextx)<dabs(ex-sx)||dabs(ey-nexty)<dabs(ey-sy)) { sx = nextx; sy = nexty; if (sx==ex&&sy==ey) { ct = i+1; break; } } } printf("%d\n",ct); } return 0;}
- codeforce 298 B Sail
- 298B Sail
- CodeForces 298B Sail
- Codeforces-298b H Sail
- Codeforces 298B Sail 题解
- B. Sail
- 文章标题 CoderForces 298B : Sail(分类)
- Sail
- Codeforces Round #180 (Div. 2)-B. Sail
- Codeforces Round #180 (Div. 2) B. Sail 【模拟】
- Codeforces Round #180 (Div. 2) B. Sail 【模拟】
- Sail CodeForces
- Time to sail!
- 2016 cherish & set sail
- bzoj1805: [Ioi2007]Sail 船帆
- bzoj 1805: [Ioi2007]Sail 船帆
- 【Sail】项目第一天简介和环境搭建
- 【Sail】第二篇热部署和代码生成
- Storm Topology的生命周期过程分析
- Python列表内涵实际中的使用介绍
- jQuery常用的元素查找方法总结
- Weka开发[9]—KMeans源码介绍
- php curl通过代理获取数据
- 298B Sail
- Spring Annotation 备忘
- Weka开发[10]—NBTree源码介绍
- opencv c++函数 imgproc模块 12 霍夫圆变换
- windows phone:Expression Blend实例中文教程(3) - 布局控件快速入门Grid
- eclipse启动tomcat无法访问
- 重载输入输出流
- ubuntu编译android4.0.3源码
- 通过Collections.sort 给 List 排序