B. New Year and North Pole

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.

Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East".

Limak isn’t sure whether the description is valid. You must help him to check the following conditions:

  • If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.
  • If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.
  • The journey must end on the North Pole.

Check if the above conditions are satisfied and print "YES" or "NO" on a single line.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 50).

The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Output

Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

Examples

Input

5
7500 South
10000 East
3500 North
4444 West
4000 North

Output

YES

Input

2
15000 South
4000 East

Output

NO

Input

5
20000 South
1000 North
1000000 West
9000 North
10000 North

Output

YES

Input

3
20000 South
10 East
20000 North

Output

NO

Input

2
1000 North
1000 South

Output

NO

Input

4
50 South
50 North
15000 South
15000 North

Output

YES

Note

Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.

题目大意:
一头熊从南极出发,每一个step都向一个方向走x米(地球直径为20000米),到达南极时只能往北走,到达北极时只能往南走,最后的终点需要为南极,问题为路径是否合法

其实只需要考虑纵坐标(南北方向)即可

这道题呗hack了一次。。。汗。。。原因是未考虑到y<0不合法的情况

代码:

#include<bits/stdc++.h>
using namespace std;
const int MAXN=60;
struct step
{
int x;
int d;
}a[MAXN];
int x,y;
// bool OK()
// {
// if(y>20000) return 0;
// return 1;
// }
int main()
{
//freopen("data.in","r",stdin);
int n;
while(cin>>n){
y=0;
string str;
for(int i=0;i<n;i++){
cin>>a[i].x;
cin>>str;
if(str=="North")a[i].d=1;
else if(str=="South")a[i].d=2;
else if(str=="West")a[i].d=3;
else if(str=="East")a[i].d=4;
}
bool flag=1;
for(int i=0;i<n;i++){
if(y>20000||y<0){
flag=0;
break;
}
if(y==0){
if(a[i].d!=2) {flag=0;break;}
}
else if(y==20000){
if(a[i].d!=1) {flag=0;break;}
}
switch(a[i].d){
case 1:y-=a[i].x;break;
case 2:y+=a[i].x;break;
case 3:/*x-=a[i].x;if(x>=40000) x%=40000;else if(x<0) x=40000+x;*/break;
case 4:/*x+=a[i].x;if(x>=40000) x%=40000;else if(x<0) x=40000+x;*/break;
}
}
if(y!=0)flag=0;
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}

CodeFroces--Good Bye 2016-B--New Year and North Pole(水题-模拟)的更多相关文章

  1. CodeFroces--Good Bye 2016-A-New Year and Hurry(水题-模拟)

    A. New Year and Hurry time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题

    A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...

  3. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  4. Good Bye 2016 A. New Year and Hurry【贪心/做题目每道题花费时间按步长为5等差增长,求剩余时间够做几道题】

    A. New Year and Hurry time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. Codeforces Good Bye 2016 E. New Year and Old Subsequence

    传送门 题意: 给出一个长度为\(n\)的串,现在有\(q\)个询问,每个询问是一个区间\([l,r]\),要回答在区间\([l,r]\)中,最少需要删多少个数,满足区间中包含\(2017\)的子序列 ...

  6. Good Bye 2016

    A - New Year and Hurry (water) #include <bits/stdc++.h> using namespace std; int main() { ]; ; ...

  7. Good Bye 2016 - D

    题目链接:http://codeforces.com/contest/750/problem/D 题意:新年烟花爆炸后会往两端45°差分裂.分裂完后变成2部分,之后这2部分继续按这种规则分裂.现在给你 ...

  8. Good Bye 2016 - C

    题目链接:http://codeforces.com/contest/750/problem/C 题意:在CF中,每个人都有个Rank值. 当Rank>=1900时,为DIV1.Rank< ...

  9. Good Bye 2016 - B

    题目链接:http://codeforces.com/contest/750/problem/B 题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走. ...

随机推荐

  1. 洛谷-乘积最大-NOIP2000提高组复赛

    题目描述 Description 今年是国际数学联盟确定的“2000――世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你 ...

  2. html 页面太长滚动时,固定页面菜单标签,或者导航标签的位置,fixed/stickUp the position

    有时你曾经需要把页面上的某些东西当页面太长发滚动的时候保留置顶位置显示,或许你有别的实现方式,我这个仅供参考, 源代码: /*global $, jQuery, alert*/ (function ( ...

  3. Java swing 如何将一个按钮放置到弹出框框的任意位置?(Absolute layout 布局的使用)

    准备: Absolute layout 绝对布局,绝对布局中控件的可以在任意位置放置 如何制作下面那种样子的 弹出框? ---------------------------------------- ...

  4. 关于python的元类

    当你创建一个类时: class Foo(Bar): pass Python做了如下的操作: Foo中有__metaclass__这个属性吗?如果是,Python会在内存中通过__metaclass__ ...

  5. ES6 之 Set数据结构和Map数据结构 Iterator和for...of循环

    ECMAScript 6 入门 Set数据结构 基本用法 ES6提供了新的数据结构Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set本身是一个构造函数,用来生成Set数据结构. va ...

  6. mysql索引类型-形式-使用时机-不足之处--注意事项

    一.索引的类型 1.普通索引   增加 create  index  index_name on table(colume(length));                       例子:cre ...

  7. 架设自己的FTP服务器 Serv-U详细配置图文教程

    转自:http://www.jb51.net/article/31635.htm 所有不是很要求安全的情况下是可以用serv_U的,当然我们也可以通过一些设置,保证serv_u安全运行.这里就分享下s ...

  8. clone()方法、深复制和浅复制

    clone方法 Java中没有明确提供指针的概念和用法,而实质上没个new语句返回的都是一个指针的引用,只不过在大部分情况下开发人员不需要关心如何去操作这个指针而已. 在实际编程中,经常会遇到从某个已 ...

  9. cocos2d-3.x 创建动画

    1.多文件帧序列动画 TrademarkAnimation.h #ifndef __TRADEMARK_ANIMATION_H__ #define __TRADEMARK_ANIMATION_H__ ...

  10. jqGrid使用整理

    jqGrid使用整理 jqGrid是一款处理表格展现的jQuery插件,支持分页.滚动加载.搜索.锁定.拖动等一系列对表格的常规操作.以下是最近项目中实践jqGrid的整理 1.引入到项目中来 jqG ...