求助!!!
查看原帖
求助!!!
215723
骗分过样例楼主2020/5/30 15:21

这个是代码,为什么只有20分???

#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;

struct xy{
	int x;
	int y;
	xy(int x,int y):x(x),y(y){}
};

int x,y;
int n,m;
char map[1005][1005];
bool vis[1005][1005];
int mp[1005][1005];

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

const int ddx[8]={0,0,1,1,1,-1,-1,-1};
const int ddy[8]={1,-1,1,0,-1,1,0,-1};

bool check(int x1,int y1,int x2,int y2){
	for(int i=0;i<8;i++){
		int x=x1,y=y1;
		while(1){
			if(map[x][y]=='X'||!(x>0&&x<=n&&y>0&&y<=m)){
				break;
			}
			else if(x==x2&&y==y2){
				return true;
			}
			x+=ddx[i],y+=ddy[i];
		}
	}
	return false;
}

int bfs(int sx,int sy,int ex,int ey){
	queue<xy> q;
	memset(mp,-1,sizeof(mp));
	memset(vis,0,sizeof(vis));
	q.push(xy(sx,sy));
	vis[sx][sy]=1;
	mp[sx][sy]=0;
	while(!q.empty()){
		xy t=q.front();
		q.pop();
		if(check(t.x,t.y,ex,ey)){
			x=t.x,y=t.y;
			return mp[t.x][t.y]; 
		}
		for(int i=0;i<4;i++){
			int nx=t.x+dx[i];
			int ny=t.y+dy[i];
			if(nx>0&&nx<=n&&ny>0&&ny<=m&&!vis[nx][ny]&&map[nx][ny]=='O'){
				vis[nx][ny]=1;
				mp[nx][ny]=mp[t.x][t.y]+1;
				q.push(xy(nx,ny));
			}
		}
	}
	return -1;
}

int main(){
	int a,b,c,d;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>map[i][j];
		}
	}
	while(cin>>a>>b>>c>>d){
		if(a==0&&b==0&&c==0&&d==0){
			break;
		}
		if(a==c&&b==d){
			cout<<"0"<<endl;
			continue;
		}
		int t=bfs(a,b,c,d);
		if(t==-1){
			cout<<"Poor Harry";
		}
		else{
			cout<<t;
		}
		cout<<endl; 
	}
	return 0;
}

求助!!!求各位dalao帮一下!!!

2020/5/30 15:21
加载中...