【Codeforces 750 B New Year and North Pole 】+ 手速
来源:互联网 发布:windows update是什么 编辑:程序博客网 时间:2024/05/24 04:28
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.
2017 第一道手速题,读懂题就没有问题~~
AC代码:
#include<bits/stdc++.h>using namespace std;char st[6];int main(){ int T,N,cut = 0,ok = 1; scanf("%d",&T); while(T--){ scanf("%d%s",&N,st); if((cut == 0 && st[0] != 'S') || (cut == 20000 && st[0] != 'N')) ok = 0; if(st[0] == 'S') cut += N; else if(st[0] == 'N') cut -= N; if(cut < 0 || cut > 20000) ok = 0; } if(!ok || cut != 0) printf("NO\n"); else printf("YES\n"); return 0;}
- 【Codeforces 750 B New Year and North Pole 】+ 手速
- 【codeforces 750B】New Year and North Pole
- 750B. New Year and North Pole
- 750B New Year and North Pole
- codeforces Good Bye 2016-B New Year and North Pole
- New Year and North Pole CodeForces
- B. New Year and North Pole
- New Year and North Pole
- goodbye 2016 B New Year and North Pole
- 【codeforces 750C】New Year and Rating
- 【codeforces 750A】New Year and Hurry
- codeforces 750C New Year and Rating
- 【codeforces 750D】New Year and Fireworks
- codeforces 750A New Year and Hurry
- Codeforces 750 C New Year and Rating
- Codeforces 750 D New Year and Fireworks
- 【codeforces 750A】New Year and Hurry
- codeforces 750New Year and Hurry
- Celery源码分析(五)----------Consumer的Blueprint
- 聊聊HDFS BlockManager的服务化改造
- 周易六十四卦——雷火丰卦
- 摄像头常见参数解释
- Activity之间,Activity与Fragment之间传递Bitmap对象时程序崩溃的原因及解决办法
- 【Codeforces 750 B New Year and North Pole 】+ 手速
- connect components in undirected graph
- c控制语句:分支和跳转(2)
- 照片瀑布流效果(js,jquery分别实现与知识点总结)
- C++第三课--之一(对象)
- MongoDB聚合
- JSP小案例之cookie管理
- 在Windows10上访问Linux部署的web项目
- Camera 图像处理原理分析