CodeForces - 750B New Year and North Pole

http://codeforces.com/problemset/problem/750/B

模拟题 

审题 在南极点 只能向北走(不能向 南 东 西) 所以也就不存在走过南极点的情况 北极点同样

然后去模拟那个走的过程 不符合条件就fail即可

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 
 6 int n;
 7 int main()
 8 {
 9     freopen("in.txt" ,"r", stdin);
10     scanf("%d", &n);
11     long long len;
12     char dir[32];
13     long long Loc = 20000;
14     bool fail = false;
15     while (n--)
16     {
17         memset(dir, 0, sizeof(dir));
18         scanf("%lld", &len);
19         scanf("%s", dir);
20         getchar();
21         if (strcmp("South", dir) && Loc == 20000)
22         {
23             fail = true;
24             break;
25         }
26         if (strcmp("North", dir) && Loc == 0)
27         {
28             fail = true;
29             break;
30         }
31         if (!strcmp(dir, "North"))
32         {
33             Loc += len;
34         }
35         if (!strcmp(dir, "South"))
36         {
37                 Loc -= len;
38         }
39         if (Loc > 20000 || Loc < 0)
40         {
41             fail = true;
42             break;
43         }
44     }
45     if (fail)
46     {
47         printf("NO\n");
48     }
49     else
50     {
51         if (Loc == 20000) printf("YES\n");
52         else printf("NO\n");
53     }
54     return 0;
55 }

 

转载于:https://www.cnblogs.com/oscar-cnblogs/p/6390241.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值