black_trees @ 2021-09-11 16:31:30
RT,除了 #2 全部RE 呜呜
#include<bits/stdc++.h>
using namespace std;
const int si_e=2e4+10;
const int si_n=2e4+10;
int n,s,ed,tot=0;
struct node{
int Next,ver,w,head;
}e[si_e];
int dist[si_n];
bool vis[si_n];
queue<int>q;
void add(int u,int v,int w){
e[++tot].ver=v,e[tot].w=w;
e[tot].Next=e[u].head,e[u].head=tot;
}
void SPFA(int s){
memset(dist,0x3f,sizeof dist);
memset(vis,false,sizeof vis);
dist[s]=0,vis[s]=true;
q.push(s);
while(!q.empty()){
int u=q.front();
q.pop();
vis[u]=false;
for(register int i=e[u].head;i;i=e[i].Next){
int v=e[i].ver,w=e[i].w;
if(dist[v]>dist[u]+w){
dist[v]=dist[u]+w;
if(!vis[v]) q.push(v),vis[v]=true;
}
}
}
}
int Hash(int x,int y){
return n*(x-1)+y;
}
int temp[si_n][si_n];
int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};
int main(){
scanf("%d",&n);
for(register int i=0;i<=n+1;++i){
temp[0][i]=temp[n+1][i]=temp[i][0]=temp[i][n+1]=1;
}
for(register int i=1;i<=n;++i){
for(register int j=1;j<=n;++j){
scanf("%1d",&temp[i][j]);
}
}
int x,xx,y,yy;
scanf("%d%d%d%d",&x,&y,&xx,&yy);
s=Hash(x,y),ed=Hash(xx,yy);
for(register int i=1;i<=n;++i){
for(register int j=1;j<=n;++j){
int now=Hash(i,j);
for(register int k=1;k<=4;++k){
int nx=i+dx[k],ny=j+dy[k],to=Hash(nx,ny);
if(temp[nx][ny]==0) add(now,to,1);
}
}
}
SPFA(s);printf("%d\n",dist[ed]);
return 0;
}
by Carnival @ 2021-09-11 16:33:58
@black_trees 这不是一道搜索题吗?
by Ryo_Yamada @ 2021-09-11 16:35:17
@black_trees 2e4+10?
by Carnival @ 2021-09-11 16:36:24
关于 SPFA
by Ryo_Yamada @ 2021-09-11 16:36:56
const int si_e=4e6+10;
const int si_n=1e3+10;
可过
by Ryo_Yamada @ 2021-09-11 16:37:29
学术也有【】瞎说 不是很懂
by Ryo_Yamada @ 2021-09-11 16:37:53
#include<bits/stdc++.h>
using namespace std;
const int si_e=4e6+10;
const int si_n=1e3+10;
int n,s,ed,tot=0;
struct node{
int Next,ver,w,head;
}e[si_e];
int dist[si_e];
bool vis[si_e];
queue<int>q;
by black_trees @ 2021-09-11 16:39:11
@BreezeEnder 操,我忘记保存了,于是交了si=100的代码
by Ryo_Yamada @ 2021-09-11 16:40:18
@black_trees 2e4 也过不了吧
by black_trees @ 2021-09-11 16:42:14
@BreezeEnder 确实,是我大意了。
忘记算了qwq
by black_trees @ 2021-09-11 16:45:31
应该是
呜呜,数据范围都不会算了