• hdu 4452简单的模拟


    比较简单的模拟题,可是我刚开始读题理解有问题,Tom will change his direction into Jerry's direction, and Jerry also will change his direction into Tom's original direction
    这句话,我想多了,以为交换的时候,Jerry得换成Tom最开始的运动方向。改了这个就过了,1Y。

    /*
     * hdu4452/win.cpp
     * Created on: 2012-10-29
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    int DIRECTION[4][4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    inline int getDirection(char c) {
        int ret;
        switch(c) {
        case 'E' : ret = 1; break;
        case 'W' : ret = 3; break;
        case 'N' : ret = 0; break;
        case 'S' : ret = 2; break;
        default: ret = 0; break;
        }
        return ret;
    }
    typedef struct State{
        int x, y;
        int s, t;
        int d;
        State(int xx, int yy, int ss, int tt, char c) {
            x = xx, y = yy;
            s = ss, t = tt;
            d = getDirection(c);
        }
    }State;
    int N;
    
    inline bool run(State &s) {
        int x = s.x + s.s * DIRECTION[s.d][0];
        int y = s.y + s.s * DIRECTION[s.d][1];
        if(x < 1) {
            x = 2 - x;
            s.d = (s.d + 2) % 4;
        }
        if(x > N) {
            x = N + N - x;
            s.d = (s.d + 2) % 4;
        }
        if(y < 1) {
            y = 2 - y;
            s.d = (s.d + 2) % 4;
        }
        if(y > N) {
            y = N + N - y;
            s.d = (s.d + 2) % 4;
        }
        s.x = x;
        s.y = y;
        return true;
    }
    
    inline bool turnleft(State &s) {
        s.d = (s.d - 1 + 4) % 4;
        return true;
    }
    
    inline bool atsamepos(State &s1, State &s2) {
        return (s1.x == s2.x) && (s1.y == s2.y);
    }
    
    inline bool changedirection(State &tom, State &jerry) {
        int temp = tom.d;
        tom.d = jerry.d;
        jerry.d = temp;
        return true;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        char c;
        int s, t, k;
        while(scanf("%d", &N) == 1 && N > 0) {
            scanf(" %c %d %d", &c, &s, &t);
            State tom(1, 1, s, t, c);
            scanf(" %c %d %d", &c, &s, &t);
            State jerry(N, N, s, t, c);
            scanf("%d", &k);
            int now = 1;
            while(now <= k) {
                run(tom);
                run(jerry);
                if(atsamepos(tom, jerry)) {
                    changedirection(tom, jerry);
                }else {
                    if(now % tom.t == 0) {
                        turnleft(tom);
                    }
                    if(now % jerry.t == 0) {
                        turnleft(jerry);
                    }
                }
                now++;
            }
            printf("%d %d\n%d %d\n", tom.x, tom.y, jerry.x, jerry.y);
        }
        return 0;
    }
  • 相关阅读:
    浏览器图片渲染优化教程
    C#把 DataTable转换为Model实体
    .NET静态变量与静态方法并发的问题
    三种方法查看MySQL数据库的版本
    Mysql 存储引擎 InnoDB与Myisam的主要区别
    dotnet core 出现Can not find runtime target for framework '.NETCoreApp,Version=v1.6' 的解决办法
    细说 C# 中的 IEnumerable和IEnumerator接口
    ASP.NET CORE dotnet run 命令使用debug方式运行
    安装了插件情况下 强制开启火狐浏览器的多进程功能
    JSON 字符串中的中括号和大括号区别详解
  • 原文地址:https://www.cnblogs.com/moonbay/p/2745493.html
Copyright © 2020-2023  润新知