题解:UVA1692 米诺陶洛斯的迷宫 Labyrinth of the Minotaur

· · 题解

这到题目比较难 我们话不多说,上代码。 代码如下:

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,m,a[1001][1001],x=1,y=1;
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    cout << "1 1" << endl;
    while(true){
        if(a[x+1][y]==1){
            cout << x+1 << " " << y << endl;
            a[x][y]=0;
            x = x+1;
        }
        else if(a[x][y+1]==1){
            cout << x << " " << y+1 << endl;
            a[x][y]=0;
            y = y+1;
        }
        else if(a[x-1][y]==1){
            cout << x-1 << " " << y << endl;
            a[x][y]=0;
            x = x-1;
        }
        else if(a[x][y-1]==1){
            cout << x << " " << y-1 << endl;
            a[x][y]=0;
            y = y-1;
        }
        else    break;
    }
    return 0;
}

请求管理员给通过