兰顿蚂蚁

oj链接:http://lx.lanqiao.cn/problem.page?gpid=T125

水题

#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>


#define I scanf
#define OL puts
#define O printf
#define F(a,b,c) for(a=b;a<c;a++)
#define FF(a,b) for(a=0;a<b;a++)
#define FG(a,b) for(a=b-1;a>=0;a--)
#define LEN 3000
#define MAX 0x06FFFFFF
#define V vector<int>

using namespace std;

int g[LEN][LEN];

int dx[4],dy[4];

int turnRight(int op){
    op--;
    if(op<0) return 3;
    return op;
}

int turnLeft(int op){
    op++;
    if(op>3) return 0;
    return op;
}

int main(){
//    http://lx.lanqiao.cn/problem.page?gpid=T125
//    freopen("D:/CbWorkspace/blue_bridge/兰顿蚂蚁.txt","r",stdin);
    //上 U
    dx[0]=-1,dy[0]=0;
    //下 D 
    dx[2]=1,dy[2]=0;
    //左 L 
    dx[1]=0,dy[1]=-1;
    //右 R 
    dx[3]=0,dy[3]=1;
    int m,n,i,j,x,y,op=0,N;
    I("%d%d",&m,&n) ;
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            I("%d",&g[i][j]);
        }
    }
    I("%d%d",&x,&y);
    char cop[2];
    I("%s",cop);
    switch(cop[0]){
        case 'D':op=2;break;
        case 'L':op=1;break;
        case 'R':op=3;break;
    }
    I("%d",&N);
    while(N--){
//        printf("%d %d
",x,y);
        if(g[x][y]){
            g[x][y]=0;
            op=turnRight(op);
            x+=dx[op];
            y+=dy[op];
        }else{
            g[x][y]=1;
            op=turnLeft(op);
            x+=dx[op];
            y+=dy[op];
        }
    }
    printf("%d %d
",x,y);
    return 0;
}
原文地址:https://www.cnblogs.com/TQCAI/p/8455015.html