84求调
  • 板块灌水区
  • 楼主wangyihao121
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/4 14:37
  • 上次更新2024/8/4 16:19:21
查看原帖
84求调
993322
wangyihao121楼主2024/8/4 14:37
#include<bits/stdc++.h>
using namespace std;
const int maxn=17000;
const int INF=2e9;
int n,m,qx,qy,zx,zy;
int dx[5]={0,1,0,-1},dx2[9]={0,1,1,1,0,-1,-1,-1};
int dy[5]={1,0,-1,0},dy2[9]={1,1,0,-1,-1,-1,0,1};
vector<int> ans[maxn];
string a[maxn];
struct node{
	int x,y,step;
};
bool ok(int x,int y){
	return x>=1&&x<=n&&y>=1&&y<=m&&a[x][y-1]=='O';
}
void bfs(int x,int y){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans[i][j]=INF;
	queue<node> q;
	q.push({x,y,0});
	ans[x][y]=0;
	while(!q.empty()){
		node a=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int xx=a.x+dx[i];
			int yy=a.y+dy[i];
			if(ok(xx,yy)&&ans[xx][yy]==INF){
				ans[xx][yy]=a.step+1;
				q.push({xx,yy,a.step+1});
			}
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans[i].resize(m+1);
	}
	while(cin>>qx>>qy>>zx>>zy){
		if(qx==0&&qy==0&&zx==0&&zy==0) break;
		bfs(zx,zy);
		for(int i=0;i<7;i++){
			int tx=qx,ty=qy;
			while(ok(tx,ty)){
				ans[qx][qy]=min(ans[qx][qy],ans[tx][ty]);
				tx+=dx2[i];
				ty+=dy2[i];
			}
		}
		if(ans[qx][qy]!=INF) cout<<ans[qx][qy]<<endl;
		else cout<<"Poor Harry"<<endl;
	}
	return 0;
}
```cpp
2024/8/4 14:37
加载中...