A10708 | New Year and North Pole
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $40000$ kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly $20000$ 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 $t_{i}$ kilometers in the direction represented by a string $dir_{i}$ 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.
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 $t_{i}$ kilometers in the direction represented by a string $dir_{i}$ 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.
输入格式
The first line of the input contains a single integer $n$ ( $1<=n<=50$ ).
The $i$ -th of next $n$ lines contains an integer $t_{i}$ and a string $dir_{i}$ ( $1<=t_{i}<=10^{6}$ , ) — the length and the direction of the $i$ -th part of the journey, according to the description Limak got.
The $i$ -th of next $n$ lines contains an integer $t_{i}$ and a string $dir_{i}$ ( $1<=t_{i}<=10^{6}$ , ) — the length and the direction of the $i$ -th part of the journey, according to the description Limak got.
输出格式
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
输入输出样例
输入 #1
5 7500 South 10000 East 3500 North 4444 West 4000 North
输出 #1
YES
输入 #2
2 15000 South 4000 East
输出 #2
NO
输入 #3
5 20000 South 1000 North 1000000 West 9000 North 10000 North
输出 #3
YES
输入 #4
3 20000 South 10 East 20000 North
输出 #4
NO
输入 #5
2 1000 North 1000 South
输出 #5
NO
输入 #6
4 50 South 50 North 15000 South 15000 North
输出 #6
YES
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.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted