求助!怎么改???
查看原帖
求助!怎么改???
502433
zsfz马润达楼主2022/4/23 20:58
#include<bits/stdc++.h>
using namespace std;
int a[1005][1005],a1[1005][1005],n,m,maxn=-1,ans;
int dx[3]={0,1,0};
int dy[3]={1,0,-1};
struct u {
	int x,y;
} sum;
u mm(int x,int y) {
	u o;
	o.x=x;
	o.y=y;
	return o;
}
queue<u> q;
bool check(int tmp) {
	q.push(mm(1,1));
	while(!q.empty()) {
		sum=q.front();
		q.pop();
        for(int i=0;i<3;i++){
        	int fx=sum.x+dx[i];
        	int fy=sum.y+dy[i];
        	if(fx==n) return true;
        	if(a[fx][fy]==99999||a1[fx][fy]!=0||a[fx][fy]>tmp) continue;
        	a1[fx][fy]=99;
        	q.push(mm(fx,fy));
		}
	}
	return false;
}
int main() {
	memset(a,99999,sizeof(a));
	memset(a1,0,sizeof(a1));
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			cin>>a[n][m];
			if(a[n][m]>maxn)
				maxn=a[n][m];
		}
	}
	int l=0,r=maxn,mid;
	while(l<=r) {
		mid=(l+r)/2;
		if(check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
		memset(a1,0,sizeof(a1));
	}
	cout<<ans;
	return 0;
}
2022/4/23 20:58
加载中...