跳到正文

题解

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

用户 1110385约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
UVA1692

版本

  1. v1当前

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

C++
#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;
}

请求管理员给通过

原文