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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情提交记录(0)
  • *山题解,第一个做出来的

    #include<bits/stdc++.h> using namespace std; struct node{ int x,y,weiax,weiay,weibx,weiby,step; bool operator<(const node& other)const{ if(x!=other.x)return x<other.x; if(y!=other.y)return y<other.y; if(weiax!=other.weiax)return weiax<other.weiax; if(weiay!=other.weiay)return weiay<other.weiay; if(weibx!=other.weibx)return weibx<other.weibx; if(weiby!=other.weiby)return weiby<other.weiby; } }; int xa,xb,ya,yb,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; string mp[10]; queue<node> q; map<node,bool> mapp; int main(){ int spacex,spacey; for(int i=0;i<2;i++){ getline(cin,mp[i]); for(int j=0;j<3;j++){ if(mp[i][j]'A'){ xa=i; ya=j; }else if(mp[i][j]'B'){ xb=i; yb=j; }else if(mp[i][j]' '){ spacex=i; spacey=j; } } } q.push({spacex,spacey,xa,ya,xb,yb,0}); while(q.size()){ node k=q.front(); q.pop(); if(k.weiaxxb&&k.weiayyb&&k.weibxxa&&k.weibyya){ cout<<k.step; return 0; } for(int i=0;i<4;i++){ node tmp; tmp.x=k.x+dx[i]; tmp.y=k.y+dy[i]; if(tmp.x<0||tmp.x>1||tmp.y<0||tmp.y>2)continue; tmp.weiax=k.weiax; tmp.weibx=k.weibx; tmp.weiay=k.weiay; tmp.weiby=k.weiby; tmp.step=k.step+1; if(tmp.xk.weiax&&tmp.yk.weiay){ tmp.weiax=k.x; tmp.weiay=k.y; }else if(tmp.xk.weibx&&tmp.y==k.weiby){ tmp.weibx=k.x; tmp.weiby=k.y; } if(mapp[tmp])continue; mapp[tmp]=1; q.push(tmp); }

    userId_undefined

    11z1m3ng1smy0n1y

    8月全勤卷王时间刺客空间掌握者时空双修者
    7阅读
    1回复
    1点赞
  • shi山代码

    userId_undefined

    11z1m3ng1smy0n1y

    8月全勤卷王时间刺客空间掌握者时空双修者
    2阅读
    1回复
    1点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页