博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #180 (Div. 2) B. Sail(简单)
阅读量:6221 次
发布时间:2019-06-21

本文共 2805 字,大约阅读时间需要 9 分钟。

B. Sail
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).

 

  • If the wind blows to the east, the boat will move to (x + 1, y).
  • If the wind blows to the south, the boat will move to (x, y - 1).
  • If the wind blows to the west, the boat will move to (x - 1, y).
  • If the wind blows to the north, the boat will move to (x, y + 1).

 

Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (x, y). Given the wind direction for t seconds, what is the earliest time they sail to (ex, ey)?

Input

The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105,  - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.

The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).

Output

If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).

Sample test(s)
input
5 0 0 1 1 SESNW
output
4
input
10 5 3 3 6 NENSWESNEE
output
-1
Note

In the first sample, they can stay at seconds 13, and move at seconds 24.

In the second sample, they cannot sail to the destination.

 第一次用C#交题~

1 using System; 2  3 class Slove 4 { 5     public static int Main() 6     { 7         int t, sx, sy, ex, ey, ans = 0; 8         string mov; 9         string str = Console.ReadLine();10         string[] sstr = str.Split(' ');11         t = Convert.ToInt32(sstr[0]);12         sx = Convert.ToInt32(sstr[1]);13         sy = Convert.ToInt32(sstr[2]);14         ex = Convert.ToInt32(sstr[3]);15         ey = Convert.ToInt32(sstr[4]);16         //Console.WriteLine(t + " " + sx + " " + sy + " " + ex + " " + ey);17         mov = Console.ReadLine();18         foreach (char c in mov)19         {20             if (sx == ex && sy == ey) break;21             ans++;22             switch (c)23             {24                 case 'E':25                     if (ex > sx) sx++;26                     break;27                 case 'S':28                     if (ey < sy) sy--;29                     break;30                 case 'W':31                     if (ex < sx) sx--;32                     break;33                 case 'N':34                     if (ey > sy) sy++;35                     break;36             }37         }38         if (sx == ex && sy == ey) Console.WriteLine(ans);39         else Console.WriteLine(-1);40         return 0;41     }42 }

 

转载地址:http://jqeja.baihongyu.com/

你可能感兴趣的文章
水果忍者(切西瓜)
查看>>
集合问题
查看>>
HTML
查看>>
渗透测试辅助工具--在线版
查看>>
Python(Handwriting)
查看>>
09-C语言选择结构(二)
查看>>
虚拟机类加载机制
查看>>
C++0X 学习之 auto
查看>>
火焰图&perf命令
查看>>
可乐鸡翅
查看>>
Spring MVC【入门】就这一篇!
查看>>
windows7 professional.iso
查看>>
postgresql存储过程
查看>>
vue.js的安装部署+cnpm install 安装过程卡住不动----亲测可用
查看>>
如何使用win7自带的备份还原以及创建系统镜像------傻瓜式教程
查看>>
类,接口,抽象类,结构
查看>>
Linux GSO逻辑分析
查看>>
ORACLE 创建表空间
查看>>
keepalived+双主架构
查看>>
robotframwork的WEB功能测试(二)—登录
查看>>