广东网站开发公司电话,html5做网站好吗,想自己做淘宝有什么网站,网络营销好找工作吗思路
既然要求最少步数#xff0c;那我们可以用bfs
如果鼠标的位置比上一行的行末位置大#xff0c;如果按上的话#xff0c;移到上一行的行末。如果鼠标的位置比下一行的行末位置大#xff0c;如果按下的话#xff0c;移到下一行的行末。
注意当鼠标位置超过当前行最大…思路
既然要求最少步数那我们可以用bfs
如果鼠标的位置比上一行的行末位置大如果按上的话移到上一行的行末。如果鼠标的位置比下一行的行末位置大如果按下的话移到下一行的行末。
注意当鼠标位置超过当前行最大值的时候要让当前位置去到最大值处。
注意需要文件读写。
代码
#includebits/stdc.h
#includecstring
#includequeue
#includeset
#includestack
#includevector
#includemap
#define ll long long
#define lhs printf(\n);
using namespace std;
const int N1e310;
const int M1e510;
const int inf0x3f3f3f3f;
int a[N];
int n;
int sx,sy,ex,ey;
int vis[114][M];
int dx[]{0,0,1,-1};
int dy[]{1,-1,0,0};
struct node
{int x,y,step;
};
void bfs(int xx,int yy)
{queuenode q;vis[xx][yy]1;q.push(node{xx,yy,0});while(q.size()){node nowq.front();q.pop(); if(now.xex and now.yey){printf(%d,now.step);return;}for(int i0;i4;i){int nxnow.xdx[i];int nynow.ydy[i];if(nya[nx]){nya[nx];}if(nx1 and nxn and ny1 and nya[nx] and vis[nx][ny]0){vis[nx][ny]1;q.push(node{nx,ny,now.step1});}}}
}
int main()
{ freopen(input.txt, r, stdin);freopen(output.txt, w, stdout);scanf(%d,n);for(int i1;in;i){scanf(%d,a[i]);a[i];}scanf(%d%d%d%d,sx,sy,ex,ey);bfs(sx,sy);return 0;
}
AC记录