• 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;
    }
  • 相关阅读:
    Oracle查看正在执行的存储过程的sid---转
    使用WITH子句重用子查询
    oracle解决显示数据的层次问题--实现数据缩进
    oracle9i、10g、11g区别 --转
    oracle10g安装在裸设备上
    在Linux系统上面创建使用裸设备的数据库
    监控Oracle数据库的常用shell脚本-转
    sql server使用维护计划定时备份完整数据库、差异数据库
    使用Advanced Installer14.3 简单打包windows窗体应用程序
    SVG Path标签 A 参数
  • 原文地址:https://www.cnblogs.com/moonbay/p/2745493.html
Copyright © 2020-2023  润新知