1 条题解
-
0
C++ :
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int map[101][101],lj[101][3],jl[101],zh[101][3]; int fx[6]={0,-1,0,1,0},fy[6]={0,0,1,0,-1}; int n,m,hd=0,tl=1,sx,sy,ex,ey,tx,ty,sum=0,ans=0; bool h=false,s=false; int pt(int x) { if(jl[x]!=0)pt(jl[x]); zh[++sum][1]=lj[x][1]; zh[sum][2]=lj[x][2]; } int main() { cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>map[i][j]; cin>>sx>>sy>>ex>>ey; map[sx][sy]=1;lj[1][1]=sx;lj[1][2]=sy;jl[1]=0; while(hd<=tl) { hd++; for(int i=1;i<=4;i++) { tx=lj[hd][1]+fx[i];ty=lj[hd][2]+fy[i]; if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&map[tx][ty]==0) { lj[++tl][1]=tx;lj[tl][2]=ty; map[tx][ty]=-1;jl[tl]=hd; if(tx==ex&&ty==ey) { pt(tl); if(zh[1][1]==zh[2][1])s=true; else h=true; for(int i=3;i<=sum;i++) { if(zh[i][1]==zh[i-1][1]&&!s){ans++;s=true;h=false;} if(zh[i][2]==zh[i-1][2]&&!h){ans++;h=true;s=false;} } cout<<ans<<endl; return 0; } } } } return 0; }
- 1
信息
- ID
- 736
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者