time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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.

【题目链接】:http://codeforces.com/contest/750/problem/B

【题解】



细节题

当前的位置只要记录横纵坐标就可以了;

一开始纵坐标位置为20000

对于左右的处理

其他情况下都不用管

如果有一个向上或向下

但是它的值大于20000,则也直接输出no

如果位置x+t>20000或x-t<0也直接输出no

如果当前位置是20000,则如果操作不是往下也直接输出NO

如果当前位置是0,如果操作不是往上则也直接输出NO

最后判断当前的位置是不是20000



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int n;
LL x; int main()
{
//freopen("F:\\rush.txt","r",stdin);
x = 20000;
rei(n);
rep1(i,1,n)
{
LL ti;
string s;
cin >> ti >> s;
if (x==20000)
{
if (s[0]!='S')
{
puts("NO");
return 0;
}
}
if (x==0)
{
if (s[0]!='N')
{
puts("NO");
return 0;
}
}
if (s[0]=='S'||s[0]=='N')
{
if (ti>20000)
{
puts("NO");
return 0;
}
}
if (s[0]=='S')
{
if (x-ti<0)
{
puts("NO");
return 0;
}
else
x-=ti;
}
if (s[0]=='N')
{
if (x+ti>20000)
{
puts("NO");
return 0;
}
else
x+=ti;
}
}
if (x==20000)
puts("YES");
else
puts("NO");
return 0;
}

【codeforces 750B】New Year and North Pole的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 764A】Taymyr is calling you

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. 5.9 enum--支持枚举类型

    enum模块提供了枚举类型的支持.枚举类型是由一个名称和一个统一值来组成.值是常量的值.它们之间能够通过名称进行比較和引用,还能够迭代訪问. 5.9.1 模块内容 本模块主要定义了两种枚举类型:Enu ...

  2. nagios 安装配置(包含nrpe端)全 (一)

    一.nagios安装: 1.安装下面命令: 这是本人监控服务时自己定义插件所用到的几个系统命令.可不安装. (1)iostat:监控磁盘IO信息: apt-getinstall sysstat (2) ...

  3. Android平台中的三种翻页效果机器实现原理

    本文给开发者集中展现了Android平台中的三种翻页效果机器实现原理,希望能够对开发者有实际的帮助价值! 第一种翻页效果如下:     实现原理: 当前手指触摸点为a,则 a点坐标为(ax,ay), ...

  4. Mongodb总结3-稍微封装一下

    上次发表的2,纯粹是Demo,演示API的用法. 今天,稍微封装了下,看得更清楚. 考虑到不容易做得很有通用性,所以封装的一般,换种场景需要直接修改代码,但是有一部分是可以复用的. 最近项目,很可能只 ...

  5. 【河南省多校脸萌第六场 A】巴什博弈?

    [链接]http://acm.nyist.me/JudgeOnline/problem.php?cid=1013&pid=5 [题意] 在这里写题意 [题解] 0..a-1 YES a..a+ ...

  6. [RxJS] Avoid mulit post requests by using shareReplay()

    With the shareReplay operator in place, we would no longer fall into the situation where we have acc ...

  7. Cocos2d 游戏状态机

    加cocos2d 是标题党. 事实上跟cocos2d无关. 1.游戏背景介绍 比方有这么一个"记忆"类的比赛游戏.你和电脑对战.轮到谁的回合,谁翻两张牌.假设两张牌一样,就消掉这两 ...

  8. 【例题 6-5 UVA 12657 】Boxes in a Line

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 双向链表模拟题. 移动的时候,要注意它就在所需要的位置的情况.那种情况不移动. (如果已经在所需位置了,还用链表的插入方式强行移动的 ...

  9. SpringBoot学习:获取yml和properties配置文件的内容(转)

    项目下载地址:http://download.csdn.net/detail/aqsunkai/9805821 (一)yml配置文件: pom.xml加入依赖: <!-- 支持 @Configu ...

  10. C#判断操作系统类型

    操作系统  PlatformID  主版本号  副版本号  Windows95  1  4  0  Windows98  1  4  10  WindowsMe  1  4  90  WindowsN ...