• HDU 4452 Running Rabbits (模拟题)


    题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向。

    现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路。 相碰: 两只兔子在K点整(即处理完一小时走的路后),在同一点,兔子A和兔子B的方向互相交换一下。 向左转 : 两只兔子有自己的转向时间T,每隔T小时,它就会向左转, 但是相碰的优先级高于它,相碰之后就不处理左转问题了。

    写模拟题还是很有趣的......练练手

    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <climits>//形如INT_MAX一类的
    #define MAX 100005
    #define INF 0x7FFFFFFF
    #define REP(i,s,t) for(int i=(s);i<=(t);++i)
    #define ll long long
    #define mem(a,b) memset(a,b,sizeof(a))
    #define mp(a,b) make_pair(a,b)
    #define L(x) x<<1
    #define R(x) x<<1|1
    # define eps 1e-5
    //#pragma comment(linker, "/STACK:36777216") ///传说中的外挂
    using namespace std;
    int n;
    struct node {
        int x,y;
        int sp,turn;
        int dir; // 0,1,2,3
    } tom,jer;
    
    int dirx[] = {-1,0,1,0};
    int diry[] = {0,1,0,-1};
    int judge(char c) {
        if(c == 'N') return 0;
        if(c == 'E') return 1;
        if(c == 'S') return 2;
        if(c == 'W') return 3;
    }
    
    void go(node &a,int d) {
        for(int i=0; i<d; i++) {
            if(a.x == 1 && a.dir == 0) {
                a.dir = 2;
            }
            if(a.x == n && a.dir == 2) {
                a.dir = 0;
            }
            if(a.y == 1 && a.dir == 3) {
                a.dir = 1;
            }
            if(a.y == n && a.dir == 1) {
                a.dir = 3;
            }
            a.x = a.x + dirx[a.dir];
            a.y = a.y + diry[a.dir];
        }
    }
    
    bool meet() {
        if(tom.x == jer.x && tom.y == jer.y) {
            swap(tom.dir,jer.dir);
            return true;
        }
        return false;
    }
    
    void move(node &a,int step,bool flag) {
        if(flag == 0) {
            if(step % a.turn == 0 && step != 0) a.dir --;
            if(a.dir < 0) a.dir = 3;
        }
        int dir = a.dir;
        if(dirx[dir] != 0) {
            int dx = abs(a.sp * dirx[dir]);
            go(a,dx);
        }
        if(diry[dir] != 0) {
            int dy = abs(a.sp * diry[dir]);
            go(a,dy);
        }
    }
    
    void solve(int h) {
        int step = 0;
        while(step < h) {
            bool flag = 0;
            if(meet()) flag = 1;
            //cout << step << endl;
            move(tom,step,flag);
            //cout << "tom: " << tom.x << ' ' << tom.y << endl;
            move(jer,step,flag);
            //cout << "jer: " << jer.x << ' ' << jer.y << endl;
            step ++;
        }
    }
    int main() {
        char c;
        int h;
        while(scanf("%d",&n) && n) {
            tom.x = 1;
            tom.y = 1;
            jer.x = n;
            jer.y = n;
            getchar();
            cin >> c;
            scanf("%d%d",&tom.sp,&tom.turn);
            tom.dir = judge(c);
            cin >> c;
            scanf("%d%d",&jer.sp,&jer.turn);
            jer.dir = judge(c);
            scanf("%d",&h);
            solve(h);
            printf("%d %d
    ",tom.x,tom.y);
            printf("%d %d
    ",jer.x,jer.y);
        }
        return 0;
    }
    


  • 相关阅读:
    触摸屏调试【转】
    Android电容屏(二):驱动调试分析【转】
    linux输入子系统简述【转】
    Linux与Android 多点触摸协议【转】
    中断下半部tasklet【转】
    【转】轻量级文本编辑器,Notepad最佳替代品:Notepad++--不错
    【转】Android开发中adb启动失败adb连接异常的解决办法 offline
    【转】Java删除文件夹和文件
    【转】图说Android的8年演变史
    【转】基于 Android NDK 的学习之旅-----数据传输(引用数据类型)
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3268497.html
Copyright © 2020-2023  润新知