• Good Bye 2016


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

    题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走。有规定在北极时只能往南方向走,同理在南极。最后走完后要回到北极。问输入的路线是否合法。

    思路:按照题意模拟就好了。定义Point为离北极的距离,初始Point为0,因为起点在北极。

    当这次行动为w/e时如果Point为0/20000(在极点)时路线不合法。

    当这次行动为n时,如果Point为20000(在南极)时路线不合法。

    当这次行动为s时,如果Point为0(在北极)时路线不合法。

    另外假设这次行动为s,并且要走的距离超过从当前位置到达南极的距离时也是不合法(不能从另一端绕圈)。同理其他情况。

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<stdio.h>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<map>
    #include<set>
    #include<time.h>
    #include<cmath>
    using namespace std;
    typedef long long int LL;
    const int MAXN = 50 + 10;
    const int MAXL = 20000;
    struct Node{
        int    dis;
        char dir[10];
    }ope[MAXN];
    int main(){
        //#ifdef kirito
        //    freopen("in.txt", "r", stdin);
        //    freopen("out.txt", "w", stdout);
        //#endif
        //    int start = clock();
        int n;
        while (scanf("%d", &n) != EOF){
            for (int i = 0; i < n; i++){
                scanf("%d %s", &ope[i].dis, ope[i].dir);
            }
            int Point = 0;  bool flag = true;
            for (int i = 0; i < n&&flag; i++){
                if (ope[i].dir[0] == 'W' || ope[i].dir[0] == 'E'){
                    if (Point == 0 || Point == MAXL){
                        flag = false;
                    }
                }
                else if (ope[i].dir[0] == 'N'){
                    if (Point == 0){
                        flag = false;
                    }
                    else{
                        if (ope[i].dis > Point){
                            flag = false;
                        }
                        else{
                            Point -= ope[i].dis;
                        }
                    }
                }
                else{
                    if (Point == MAXL){
                        flag = false;
                    }
                    else{
                        if (ope[i].dis > (MAXL - Point)){
                            flag = false;
                        }
                        else{
                            Point += ope[i].dis;
                        }
                    }
                }
                //printf("%d
    ", Point);
            }
            printf(flag == true && Point == 0 ? "YES
    " : "NO
    ");
        }
        //#ifdef LOCAL_TIME
        //    cout << "[Finished in " << clock() - start << " ms]" << endl;
        //#endif
        return 0;
    }
  • 相关阅读:
    读財报:交易额增长111%的京东,为毛还是亏?
    HDU 1548 A strange lift 搜索
    linux两台server远程copy文件
    Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离具体解释
    js事件防止冒泡
    LeetCode Rotate Array
    ARM架构授权和IP核授权有什么不一样啊?
    Linux系统结构 详解
    mount -o
    ARM开发板系统移植-----u-boot的编译
  • 原文地址:https://www.cnblogs.com/kirito520/p/6238953.html
Copyright © 2020-2023  润新知