New Year and North Pole

2024-01-13 19:38
文章标签 new year north pole

本文主要是介绍New Year and North Pole,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这个题目注意把几个判断条件设置好就行了

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.

#include<stdio.h>
#include<stdlib.h>
int main()
{int n,pos=0,flag=0;scanf("%d",&n);while(n--){int len;char dir[10]={0};scanf("%d %s",&len,dir);if(flag)continue;       if((dir[0]!='S'&&pos==0)||(dir[0]!='N'&&pos==20000))flag=1;        if(dir[0]=='S')pos+=len;if(dir[0]=='N')pos-=len;if(pos<0||pos>20000)flag=1;}if(flag||pos)printf("NO");elseprintf("YES");return 0;
}

这篇关于New Year and North Pole的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/602559

相关文章

java线程深度解析(一)——java new 接口?匿名内部类给你答案

http://blog.csdn.net/daybreak1209/article/details/51305477 一、内部类 1、内部类初识 一般,一个类里主要包含类的方法和属性,但在Java中还提出在类中继续定义类(内部类)的概念。 内部类的定义:类的内部定义类 先来看一个实例 [html]  view plain copy pu

string字符会调用new分配堆内存吗

gcc的string默认大小是32个字节,字符串小于等于15直接保存在栈上,超过之后才会使用new分配。

List list = new ArrayList();和ArrayList list=new ArrayList();的区别?

List是一个接口,而ArrayList 是一个类。 ArrayList 继承并实现了List。 List list = new ArrayList();这句创建了一个ArrayList的对象后把上溯到了List。此时它是一个List对象了,有些ArrayList有但是List没有的属性和方法,它就不能再用了。而ArrayList list=new ArrayList();创建一对象则保留了A

vue原理分析(六)--研究new Vue()

今天我们来分析使用new Vue() 之前研究时,只是说是在创建一个实例。并没有深入进行研究 在vue的源码中找下Vue的构造函数 function Vue(options) {if (!(this instanceof Vue)) {warn$2('Vue is a constructor and should be called with the `new` keyword');}thi

GTK中创建线程函数g_thread_new和g_thread_create的区别

使用GThread函数,需要引用glib.h头文件。 这两个接口的核心区别就是  g_thread_create 是旧的接口,现在已经不使用了,而g_thread_new是新的接口,建议使用。 g_thread_create: g_thread_create has been deprecated since version 2.32 and should not be used in n

New的VC编译器实现

当我们调用 new 的时候,例如 int *p = new int; 时,编译器到底作了什么工作呢?跟进断点看一看。   (在 vc debug模式下 ) double *p1 = new double ; 00411A6E  push        8    00411A70  call        operator new (4111B8h) 00411A75  add

Python方法:__init__,__new__,__class__的使用详解

转自:https://blog.csdn.net/qq_26442553/article/details/82464682 因为python中所有类默认继承object类。而object类提供了了很多原始的内建属性和方法,所以用户自定义的类在Python中也会继承这些内建属性。可以使用dir()函数可以查看,虽然python提供了很多内建属性但实际开发中常用的不多。而很多系统提供的内建属性实际

linux 环境下使用PHP OpenSSL扩展函数openssl_pkey_new(),返回false的原因

<?php$config = array('private_key_bits' => 2048,);$res = openssl_pkey_new($config); $res返回false的时候,检查发现,是linux系统缺少了openssl的配置,解决方法如下: 直接将php -m 中 Openssl 中的xx.conf 配置移动到对应的目录,然后重启php-fpm 完美解决

【js面试题】说说new操作符具体干了什么?

JavaScript中的new操作符:深入解析与自定义实现 在JavaScript中,new操作符是一个核心概念,用于创建一个实例对象。理解new的工作原理不仅有助于我们更好地掌握JavaScript的面向对象编程,还能让我们在需要时自定义构造函数的行为。本文将从new是什么、其工作流程、存在的必要性、解决的问题以及如何手动实现一个new操作符来深入探讨这一主题。 什么是new操作符? ne