求调
  • 板块灌水区
  • 楼主__KevinMZ__
  • 当前回复0
  • 已保存回复1
  • 发布时间2024/11/29 18:50
  • 上次更新2024/11/29 20:43:22
查看原帖
求调
1358215
__KevinMZ__楼主2024/11/29 18:50
#include <bits/stdc++.h>
using namespace std;
char _map[1010][1010];
int b[1020100][3];
bool st[1010][1010];
int m,z,n,a1,b1,a2,b2;
int s;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
bool nbsp;
void dfs(int x, int y, int step)
{
    //cout << x << ' ' << y << endl;
    
    
	
	if(x == n && y == m) 
    {
    nbsp=true;
 	cout << "(1,1)";
 	for(int i = 2; i <= step - 1; i++)
    {
        cout << "->(" << b[i][1] << "," << b[i][2]<<")";
    } 
 	cout << endl; return;
    }
    
	for(int i = 0; i < 4; i++)
	{//if(z == 100) return;
		int nx = x + dx[i], ny = y + dy[i];
		if(nx >= 1 and ny >= 1 and nx <= n and
		ny <= m and st[nx][ny] == 0 and _map[nx][ny]-'0')
        {
            if(!st[nx][ny])
            {
                b[step][1] = nx;b[step][2] = ny;
                st[nx][ny] = 1;
            dfs(nx, ny, step + 1);
            st[nx][ny] = 0;}
        }
    
    
}}

int main(){
	cin>>n >> m;
    b[1][1] = 1;b[1][2] = 1;
    st[1][1] = 1;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++)cin>>_map[i][j];
	cin>>a1>>b1>>a2>>b2;
    dfs(a1, b1, 2);
    if(!nbsp)cout<<-1;
	return 0;
}

[link]

2024/11/29 18:50
加载中...