3 条题解
-
0Guest LV 0
-
1
#include<bit/stdc++.h>
using namespace std;
char a[][1000];
int d[4]={-1,0,0,1},z[4]={0,-1,1,0};
struct data{
int in,jn,ans;
};
queue<data>q;
int has[80][800],ans1,f;
int main(){
int n,m;
memseta,' ',sizef(a));
cin>>m>>n;
for( i=1; i<=n; i++){
getchar();
fo(int j=1; j<=m; j++scanf("%c",&a[i][j]);
}
int x,y,x1,y1;
while(cin>>y>>x>>y1>>x1 && x!=0){
while(!q.empty())q.pop();
memset(has,0,sizeof(has));
ans1=0;
q.push(data{x,y,0});
has[x][y]=1;
a[x1][y1]=' ';
while(!q.empty()){
data t=q.front();
q.pop();
if(t.in==x1&&t.jn==y1){
ans1=t.ans;
break;
}
for(int i=0;i<4;i++){
int xn=t.in+d[i];
int yn=t.jn+z[i];
while( xn>=0 && xn<=n+1 && yn>=0 && yn<=m+1 && a[xn][yn]==' '){
if(has[xn][yn]==0){
q.push(data {xn,yn,t.ans+1});
has[xn][yn]=1;
}
xn=xn+d[i];
yn=yn+z[i];
}
}
a[x1][y1]='X'
cout<<ans1<<endl
}
} -
0
#include<algorithm>
#include<iostream>
#include<string.h>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
char a[1000][1000];
int d[4]={-1,0,0,1},z[4]={0,-1,1,0};
struct data{
int in,jn,ans;
};
queue<data>q;
int has[800][800],ans1,f;
int main(){
int n,m;
memset(a,' ',sizeof(a));
cin>>m>>n;
for(int i=1; i<=n; i++){
getchar();
for(int j=1; j<=m; j++)scanf("%c",&a[i][j]);
}
int x,y,x1,y1;
while(cin>>y>>x>>y1>>x1 && x!=0){
while(!q.empty())q.pop();
memset(has,0,sizeof(has));
ans1=0;
q.push(data{x,y,0});
has[x][y]=1;
a[x1][y1]=' ';
while(!q.empty()){
data t=q.front();
q.pop();
if(t.in==x1&&t.jn==y1){
ans1=t.ans;
break;
}
for(int i=0;i<4;i++){
int xn=t.in+d[i];
int yn=t.jn+z[i];
while( xn>=0 && xn<=n+1 && yn>=0 && yn<=m+1 && a[xn][yn]==' '){
if(has[xn][yn]==0){
q.push(data {xn,yn,t.ans+1});
has[xn][yn]=1;
}
xn=xn+d[i];
yn=yn+z[i];
}
}
}
a[x1][y1]='X';
cout<<ans1<<endl;
}
} -
-1
#include<bits/stdc++.h> using namespace std; char a[1000][1000]; int d[4]={-1,0,0,1},z[4]={0,-1,1,0}; struct data{ int in,jn,ans; }; queue<data>q; int has[800][800],ans1,f; int main(){ int n,m; memset(a,' ',sizeof(a)); cin>>m>>n; for(int i=1; i<=n; i++){ getchar(); for(int j=1; j<=m; j++)scanf("%c",&a[i][j]); } int x,y,x1,y1; while(cin>>y>>x>>y1>>x1 && x!=0){ while(!q.empty())q.pop(); memset(has,0,sizeof(has)); ans1=0; q.push(data{x,y,0}); has[x][y]=1; a[x1][y1]=' '; while(!q.empty()){ data t=q.front(); q.pop(); if(t.in==x1&&t.jn==y1){ ans1=t.ans; break; } for(int i=0;i<4;i++){ int xn=t.in+d[i]; int yn=t.jn+z[i]; while( xn>=0 && xn<=n+1 && yn>=0 && yn<=m+1 && a[xn][yn]==' '){ if(has[xn][yn]==0){ q.push(data {xn,yn,t.ans+1}); has[xn][yn]=1; } xn=xn+d[i]; yn=yn+z[i]; } } } a[x1][y1]='X'; cout<<ans1<<endl; } }
- 1
信息
- 难度
- 7
- 分类
- (无)
- 标签
- 递交数
- 24
- 已通过
- 6
- 通过率
- 25%
- 上传者