编辑代码

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int a,mp[101][101];
int t[100003];
int y[100003];
int cnt;
int len =2,dir=3,die=0;
const int dx[5]={0,0,-1,0,1};
const int dy[5]={0,-1,0,1,0};
int nx=0,ny=1;
int px=1,py=2;
int cheek(int x,int yy){
    if(x<1 || x>a || yy<1 || yy>a)
    return 1;
    if(cnt+1-mp[x][yy]<len)
    return 1;
    return 0;
}
void work(){
    if(die)return;
    px+=nx;
    py+=ny;
    die=cheek(px,py);
    if(die)return;
    mp[px][py]=++cnt;

}
void show(){
    for(int i=1;i<=a;i++){
        for(int j=1;j<=a;j++){
            if(mp[i][j]!=0 && mp[i][j]>=cnt-len+1)
                putchar('o');
            else
                putchar('.');

        }
        puts("");
    }
}
int main(){
    mp[1][1]=++cnt;
    mp[1][2]=++cnt;
    int n,m,op,xx;
    char s[3];
    scanf("%d",&a);
    scanf("%d%d",&n,&m);
    while(n--){
        scanf("%d%d",&op,&xx);
        if(op==1){
            t[xx]=1;
            scanf("%s",s);
            if(s[0]=='L')
                y[xx]=1'
            else if(s[0]=='U')
                y[xx]=2;
            else if(s[0]=='R')
                y[xx]=3;
            else
                y[xx]=4;
        }
        else t[xx]=2;
    }
    for(int tm=1;tm<=m;++tm){
        if(t[tm]==1){
            if(y[tm]%2!=dir%2){
                dir=y[tm];
                nx=dx[y[tm]];
                ny=dy[y[tm]];

            }
        }
        else if(t[tm]==2)
            ++len;
        work();
        if(die) break;
    }
    show();
    return 0;
}