POJ 3626 Mud Puddles
来源:互联网 发布:淘宝直通车与淘宝联盟 编辑:程序博客网 时间:2024/05/01 11:50
Description
Farmer John is leaving his house promptly at 6 AM for his daily milking of Bessie. However, the previous evening saw a heavy rain, and the fields are quite muddy. FJ starts at the point (0, 0) in the coordinate plane and heads toward Bessie who is located at (X, Y) (-500 ≤ X ≤ 500; -500 ≤ Y ≤ 500). He can see all N (1 ≤ N ≤ 10,000) puddles of mud, located at points (Ai, Bi) (-500 ≤ Ai ≤ 500; -500 ≤ Bi ≤ 500) on the field. Each puddle occupies only the point it is on.
Having just bought new boots, Farmer John absolutely does not want to dirty them by stepping in a puddle, but he also wants to get to Bessie as quickly as possible. He's already late because he had to count all the puddles. If Farmer John can only travel parallel to the axes and turn at points with integer coordinates, what is the shortest distance he must travel to reach Bessie and keep his boots clean? There will always be a path without mud that Farmer John can take to reach Bessie.
Input
* Line 1: Three space-separate integers: X, Y, and N.
* Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi
Output
* Line 1: The minimum distance that Farmer John has to travel to reach Bessie without stepping in mud.
Sample Input
1 2 70 2-1 33 11 14 2-1 12 2
Sample Output
11
就一BFS,搞得。。开始以为1000*1000的点暴搜TLE。
结果=。=,都加了500,弄到第一象限去了。。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<queue>using namespace std;int mp[1100][1100];int dr[4][2]={{-1,0},{0,1},{1,0},{0,-1}};int n1,m1,n2,m2,t;int ex,ey;struct node{ int x,y; int step;};void bfs(){ node st,ed; queue<node>q; st.x=500; st.y=500; st.step=0; q.push(st); while(!q.empty()) { st=q.front(); q.pop(); if(st.x==ex&&st.y==ey) { printf("%d\n",st.step); return ; } for(int i=0;i<4;i++) { int xx=st.x+dr[i][0]; int yy=st.y+dr[i][1]; if(xx>=0&&xx<=1000&&yy>=0&&yy<=1000&&mp[xx][yy]==0) { ed.x=xx; ed.y=yy; ed.step=st.step+1; mp[xx][yy]=1; q.push(ed); } } }}int main(){ int u,v; while(~scanf("%d%d%d",&ex,&ey,&t)) { ex+=500;ey+=500; memset(mp,0,sizeof(mp)); for(int i=0;i<t;i++) { scanf("%d%d",&u,&v); mp[u+500][v+500]=1; } bfs(); } return 0;}
- POJ 3626 Mud Puddles
- POJ 3626 Mud Puddles (BFS)
- poj 3626 Mud Puddles (简单BFS)
- POJ 3626 Mud Puddles(bfs)
- POJ 3626 Mud Puddles(BFS)【模板】
- POJ 3626 Mud Puddles 练习 BFS 宽度优先搜索
- POJ 3626 Mud Puddles(超简单BFS)
- poj3626 Mud Puddles
- USACO 2007 Dec Silver Mud Puddles bfs or A-star
- X-MUD
- Lesson 52: Mud is mud 实事求是
- mud的颜色
- MUD中安全谈
- [zz]古老的Mud
- 从MUD到SNS
- 【转的】MUD驱动程序
- Big Ball of Mud
- MUD(制造者用法描述)
- UIAutomator remote debug方法
- js中 正则表达式
- 数组求和-空间换时间-1062
- 白话经典算法系列之六 快速排序 快速搞定
- 考虑自身的经历多少政策
- POJ 3626 Mud Puddles
- QT的学习之路——QString的基础
- 萨拉跨境快速发财
- Android contentProvider
- 返回值是函数指针
- 输入3个学员的姓名,动态分配内存保存学员姓名,并在最后输出
- HDU 1253---胜利大逃亡【BFS三维数组】
- CPU的大小端模式
- AC自动机之初学习