acgo题库
  • 首页
  • 题库
  • 学习
  • 天梯
  • 备赛

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
  • 资讯
  • 竞赛
  • 讨论
  • 团队
  • 商城
登录
注册
题目详情提交记录(0)
  • 题解

    #include<bits/stdc++.h> using namespace std; namespace HQ{ #define int long long void init(){ iossync_with_stdio(0); cin.tie(0); cout.tie(0); }struct node{ int x,y,step=0; }l,r; int dx[]={-1,0,1,0}; int dy[]={0,1,0,-1}; int n,m,a,b; int mp[1145][1145]; int sx,sy,ex,ey; bool vis[1145][1145]; int local[114514][15]; int times[1145][1145]; void Main(){ init(); cin>>n>>m>>a>>b; queue<node>q; for(int i=1;i<=a;i++){ int x,y; cin>>x>>y; q.push({x,y}); vis[x][y]=1; }for(int i=1;i<=b;i++){ cin>>local[i][1]>>local[i][2]; }while(q.size()){ r=q.front(); q.pop(); for(int i=0;i<4;i++){ l.x=r.x+dx[i]; l.y=r.y+dy[i]; if(l.x>=1 and l.x<=n and l.y>=1 and l.y<=m and !vis[l.x][l.y]){ l.step=r.step+1; q.push(l); vis[l.x][l.y]=1; } }times[r.x][r.y]=r.step; }for(int i=1;i<=b;i++){ cout<<times[local[i][1]][local[i][2]]<<'\n'; } return; } }signed main(){ HQMain(); return (LLONG_MAX+LLONG_MIN+1LL)*114514LL/signed(2147483648); }

    userId_undefined
    未知
    模拟·模拟练习生倔强青铜冒泡宗师→排序元老
    3阅读
    0回复
    0点赞
暂无数据

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

首页