码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj1627 / P2873 [USACO07DEC]泥水坑Mud Puddles

时间:2018-10-27 18:47:56      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:class   splay   pac   isp   gis   efi   zoj   入门   判断   

P2873 [USACO07DEC]泥水坑Mud Puddles

bfs入门。

对于坐标为负的情况,我们可以给数组下标加上$abs(min(minx,miny))$转正(根据题意判断)

技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<queue>
 5 #define re register
 6 using namespace std;
 7 #define M 502
 8 const int d1[4]={0,1,0,-1};
 9 const int d2[4]={1,0,-1,0};
10 struct node{int x,y,t;}; queue <node> h;
11 int tx,ty,n; bool vis[M*2+5][M*2+5];
12 int main(){
13     scanf("%d%d%d",&tx,&ty,&n); tx+=M;ty+=M; int q1,q2;
14     for(int i=1;i<=n;++i) scanf("%d%d",&q1,&q2),vis[q1+M][q2+M]=1;
15     h.push((node){M,M,0}); vis[M][M]=1;
16     while(!h.empty()){
17         node u=h.front(); h.pop();
18         for(int i=0;i<4;++i){
19             int r1=u.x+d1[i],r2=u.y+d2[i];
20             if(vis[r1][r2]) continue;
21             if(r1==tx&&r2==ty){
22                 printf("%d",u.t+1);
23                 return 0;
24             }h.push((node){r1,r2,u.t+1}),vis[r1][r2]=1;
25         }
26     }
27 }
View Code

 

bzoj1627 / P2873 [USACO07DEC]泥水坑Mud Puddles

标签:class   splay   pac   isp   gis   efi   zoj   入门   判断   

原文地址:https://www.cnblogs.com/kafuuchino/p/9862611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!