0
已解决
汪宇航
新手启示者
新手启示者
3788 迷宫问题2
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
int n,m,t,sx,sy,ex,ey,ans=0x3f3f3f3f;
int dir[5][2]={{0},{1,0},{0,1},{1,1}};
int vis[25][25];
bool a[25][25];
void dfs(int x,int y,int cnt){
if(cnt>=ans) return ;//剪枝
if(x==ex&&y==ey){
ans=min(ans,cnt);
return ;
}
for(int i=1;i<=3;i++){
int dx=x+dir[i][0],dy=y+dir[i][1];
if(dx>=1&&dy>=1&&dx<=n&&dy<=m && !vis[dx][dy]&&!a[dx][dy]){
a[dx][dy]=true;
dfs(dx,dy,cnt+1);
a[dx][dy]=false;
}
}
return ;
}
int main(){
scanf("%d%d%d%d",&n,&m,&sy,&ey);
sx=1,ex=m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&vis[i][j]);
}
}
if(vis[sx][sy]||vis[ex][ey]){
cout<<-1;
return 0;
}
a[sx][sy]=true;
dfs(sx,sy,0);
if(ans!=0x3f3f3f3f)printf("yes");
else printf("no");
return 0;
}
怎么都这样了样例都没过啊???啊啊啊
0
已采纳
李志皓
初级守护
初级守护
李志皓在2021-08-27 10:51:29追加了内容
很简单呀
李志皓在2021-08-27 10:57:06追加了内容
#include<iostream>
using namespace std;
定义 m,n,x,y,a[15][15];
定义 f[15][15];
int main(){
输入>>m>>n>>x>>y;
for(循环1到m){
for(循环1到n){
输入>>f[i][j];
}
}
if(f[1][x]==1){
cout<<"no";
return 0;
}
a[1][x]=1;
for(循环2到m){
for(循环1到n){
a[i][j]=a[i-1][j]+a[i-1][j+1]+a[i-1][j-1];
if(f[i][j]==1) a[i][j]=0;
}
}
if(a[m][y]!=0) cout<<"yes";
else cout<<"no";
return 0;
}
李志皓在2021-08-27 14:02:29追加了内容
求采纳
0
0