USACO 2012 March Silver Tractor /// 优先队列BFS oj21567
题目大意:
输入n,(x,y);n为阻挡的草堆数量,(x,y)为开始时拖拉机所在的位置
接下来n行每行一个坐标(a,b);为各个草堆的坐标
输出拖拉机要回到原点(0,0)需要移动的草堆数量
7 6 3
6
2
5 2
4 3
2 1
7 3
5 4
6 4
1
INPUT DETAILS:
The tractor starts at
(6,3). There are 7 bales of hay, at positions (6,2), (5,2), (4,3), (2,1),
(7,3), (5,4), and (6,4).
OUTPUT
DETAILS:
Farmer John only needs to
remove one bale of hay to free his tractor.
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <queue>
#include <functional>
using namespace std;
struct NODE
{
int sp,x,y;
NODE(){};
NODE(int spi,int xi,int yi):
sp(spi),x(xi),y(yi){};
bool operator<(const NODE& p)const{
return sp>p.sp; /// 升序排序这里应该是 大于号!!
}
};
int mov[][]={{,},{,-},{,},{-,}};
int G[][];
int st,ed,n;
bool bound(int x,int y)
{
return x==||y==||x==||y==;
}
int main()
{
while(~scanf("%d",&n))
{
scanf("%d%d",&st,&ed);
memset(G,,sizeof(G));
for(int i=;i<=n;i++)
{
int a,b; scanf("%d%d",&a,&b);
G[a][b]=;
} priority_queue < NODE > q;
q.push(NODE(,st,ed));
G[st][ed]=-;
while(!q.empty())
{
NODE tmp=q.top(); q.pop(); if(bound(tmp.x,tmp.y))
{
printf("%d\n",tmp.sp);
break;
}//printf("%d %d %d\n",tmp.x,tmp.y,tmp.sp); for(int i=;i<;i++)
{
int nowx=tmp.x+mov[i][],
nowy=tmp.y+mov[i][],
nowsp=tmp.sp; if(G[nowx][nowy]==-) continue; if(G[nowx][nowy]) nowsp++;
G[nowx][nowy]=-; q.push(NODE(nowsp,nowx,nowy));
//printf("%d %d %d\n",nowx,nowy,nowsp);
}
}
} return ;
}
USACO 2012 March Silver Tractor /// 优先队列BFS oj21567的更多相关文章
- USACO翻译:USACO 2012 FEB Silver三题
USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...
- USACO翻译:USACO 2014 MARCH Silver三题
USACO 2014 MARCH 一.题目概览 中文题目名称 农田灌溉 懒牛 牛叫 英文题目名称 irrigation lazy mooomoo 可执行文件名 irrigation lazy mooo ...
- [USACO 2012 Mar Silver] Landscaping【Edit Distance】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=126 好题啊好题,一开始就输给了这道题的想法! 先把原始状态以及目标状态换 ...
- [USACO 2012 Jan Silver] Bale Share【DP】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=107 没想到太不应该了,真的不应该啊! f[i][j][k]表示前i个包, ...
- [USACO 2012 Jan Silver] Delivery Route【拆点】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=106 这道题还真是完全没思路,真的不知道怎么做,但是看了题解后恍然大悟. ...
- USACO翻译:USACO 2012 JAN三题(2)
USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...
- USACO翻译:USACO 2012 JAN三题(1)
USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- USACO翻译:USACO 2013 DEC Silver三题
USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...
随机推荐
- 为什么要使用动态链接库(DLL)
为什么要使用动态链接库(DLL) 第一章 为什么要使用动态链接库(DLL) top 提起DLL您一定不会陌生,在Windows中有着大量的以DLL为后缀的文件,它们是保证Windows正常运行和维 ...
- 使用Sonatype Nexus搭建Maven私服后,如何添加第三方JAR包
使用Sonatype Nexus搭建Maven私服后如何添加第三方JAR包 步骤如下 1.打开nexus地址,进行登录 2.登录Nexus后,点击右侧的“Repositories”,显示当前Nexus ...
- 仿淘宝使用flex布局实现页面顶部和底部的固定布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- NX二次开发-UFUN遍历函数UF_OBJ_cycle_all
NX11+VS2013 #include <uf.h> #include <uf_obj.h> #include <uf_modl.h> #include < ...
- Go将统治下一个10年?Go语言发展现状分析
“本文是国内Go语言大中华区首席布道师——许式伟,在QCon2015上海站上的分享.他预测Go语言10年内一定会超过C和java,并且统治这一个10年. Go语言语法及标准库变化 Go从1.0版本到现 ...
- flutter 动态申请权限
https://pub.flutter-io.cn/packages/permission_handler https://www.jianshu.com/p/fa68876fbdfd 例 Futur ...
- DXP 快捷键
EC 复制 EY array paste TU: update
- IntelliJ IDEA无法创建springboot项目解决办法
最佳解决办法:IntelliJ IDEA---右键---以管理员身份运行. 方法二: 1.打开控制面板--系统和安全--windows防火墙 2.找到自己的默认浏览器,打勾,这里是谷歌浏览器 3.打开 ...
- vue点击跳转拨号界面
<a :href="'tel:' + VipInfo.HotelPhone" style="text-decoration:none;color:black;opa ...
- centos yum install 找不到软件包
yum install epel-release 然后再试试yum install 其他安装包