文章

7

粉丝

0

获赞

10

访问

1.2k

头像
机器人走迷宫 题解:模拟
P1675 中南大学/中山大学机试题
发布于2026年2月14日 21:30
阅读数 150

#include<bits/stdc++.h>
using namespace std;
const int maxn=15;
char mpt[maxn][maxn];
int flag[maxn][maxn];
int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
    int w,h;
int tonum(char temp){
    if(temp=='U') return 0;
    if(temp=='R') return 1;
    if(temp=='D') return 2;
    if(temp=='L') return 3;
}
bool isvalid(int x, int y) {
    if (x < 1 || x > w || y < 1 || y > h) return false; // 边界
    if (mpt[x][y] == '*') return false; // 陷阱不可走
    if (flag[x][y]) return false; // 已访问不可走
    return true;
}
int func(int sx,int sy,int initdir){
    memset(flag,0,sizeof(flag));
    flag[sx][sy]=1;
    int cnt=1;
    while(1){
        int nx1=sx+dir[initdir][0];
        int ny1=sy+di...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发