70分求解

P1605 迷宫

为什么我复制你的交上去是0分呢
by Lhc_fl @ 2019-07-24 10:39:15


您是不是忘记判断边界了……
by Lhc_fl @ 2019-07-24 10:39:54


@[Lhc_fl](/space/show?uid=55684) 我刚又交了一遍,70分,可能是我代码粘错了? 2、7、8三个点wa! [捕获](C:\Users\Admin\Desktop\捕获.png)
by Kanoshuuya @ 2019-07-24 10:48:35


@[Lhc_fl](/space/show?uid=55684) ```cpp #include <bits/stdc++.h> using namespace std; int vis[10][10]; int dx[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; int n,m,t,ans = 0,ex,ey; int isOK(int x,int y){ if(x<=n&&x>0&&y<=m&&y>0) return 1; else return -1; } void dfs(int x,int y){ if(x==ex&&y==ey){ ans++; } else{ for(int i=0;i<4;i++){ int xx = x+dx[i][0]; int yy = y+dx[i][1]; if(vis[xx][yy]!=1&&isOK(xx,yy)==1){ vis[xx][yy] = 1; dfs(xx,yy); vis[xx][yy] = 0; } } } } int main() { memset(vis,0,sizeof(vis)); int x,y,a,b; cin>>n>>m>>t; cin>>x>>y; cin>>ex>>ey; for(int i=0;i<t;i++){ cin>>a>>b; vis[a][b] = 1; } dfs(x,y); cout<<ans<<endl; return 0; } ```
by Kanoshuuya @ 2019-07-24 10:49:07


@[Lhc_fl](/space/show?uid=55684) 后边这个是70分,之前的那个代码判边界写错了
by Kanoshuuya @ 2019-07-24 10:50:22


我先粘下我的,做久了不记得了……QwQ ```cpp #include<bits/stdc++.h> using namespace std; int n,m,sum,sx,sy,fx,fy; int a[10][10]; bool d[10][10]; void dfs(int x,int y){ if(x==fx && y==fy){sum++;return;} if(x<1 || y<1 || x>n || y>m){return;} if(d[x][y]==1 || a[x][y]==1){return;} d[x][y]=1; dfs(x+1,y); dfs(x,y+1); dfs(x-1,y); dfs(x,y-1); d[x][y]=0; } int main(){ int t; cin>>n>>m>>t; cin>>sx>>sy>>fx>>fy; for(int i=1;i<=t;i++){ int x,y; cin>>x>>y; a[x][y]=1; } if(a[fx][fy]==1){cout<<0;return 0;} dfs(sx,sy); cout<<sum; } ```
by Lhc_fl @ 2019-07-24 10:54:16


@[Lhc_fl](/space/show?uid=55684) ~~出奇地相似~~ 刚才也偷懒不想用两个数组分别存迷宫和标记,难道是因为这个emmmmm
by Kanoshuuya @ 2019-07-24 10:58:36


@[Kanoshuuya](/space/show?uid=82293) 确实出奇的相似,只是我当时错的时候只有50分hmmm
by Lhc_fl @ 2019-07-24 11:01:04


啊我明白了,确实需要两个数组,不然你就把障碍给消掉了
by Lhc_fl @ 2019-07-24 11:02:24


怎么感觉我又看错了……
by Lhc_fl @ 2019-07-24 11:05:04


| 下一页