acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 题解

    #include<bits/stdc++.h> using namespace std; int m,n,step; int a[105][105]; int vis[105][105]; int h[13][2]={0,0,-2,-1,-2,-2,-1,-2,1,-2,2,-2,2,-1,2,1,2,2,1,2,-1,2,-2,2,-2,1}; struct node{ int x,y; }s; void bfs(int x,int y){ queue<node> q; s.x=x,s.y=y; q.push(s); while(!q.empty()){ s=q.front(); q.pop(); x=s.x,y=s.y; for(int i=1;i<=12;i++){ int hx=x+h[i][0]; int hy=y+h[i][1]; if(hx>=1&&hx<=100&&hy>=1&&hy<=100&&!vis[hx][hy]){ s.x=hx,s.y=hy; q.push(s); a[hx][hy]=a[x][y]+1; vis[hx][hy]=1; if(hx1&&hy1){ step=a[hx][hy]; return; } } } } } int main(){ while(cin>>m>>n&&(m!=1||n!=1)){ step=0; memset(vis,0,sizeof(vis)); memset(a,0,sizeof(a)); bfs(m,n); cout<<step<<endl; } return 0; }

    userId_undefined

    IV-Luca(卢卡)

    模拟·模拟练习生
    1阅读
    0回复
    0点赞
首页