题目大意:

输入n,(x,y);n为阻挡的草堆数量,(x,y)为开始时拖拉机所在的位置

接下来n行每行一个坐标(a,b);为各个草堆的坐标

输出拖拉机要回到原点(0,0)需要移动的草堆数量

Sample Input

7 6 3
6
2
5 2
4 3
2 1
7 3
5 4
6 4

Sample Output

1

Hint

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的更多相关文章

  1. USACO翻译:USACO 2012 FEB Silver三题

    USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...

  2. USACO翻译:USACO 2014 MARCH Silver三题

    USACO 2014 MARCH 一.题目概览 中文题目名称 农田灌溉 懒牛 牛叫 英文题目名称 irrigation lazy mooomoo 可执行文件名 irrigation lazy mooo ...

  3. [USACO 2012 Mar Silver] Landscaping【Edit Distance】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=126 好题啊好题,一开始就输给了这道题的想法! 先把原始状态以及目标状态换 ...

  4. [USACO 2012 Jan Silver] Bale Share【DP】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=107 没想到太不应该了,真的不应该啊! f[i][j][k]表示前i个包, ...

  5. [USACO 2012 Jan Silver] Delivery Route【拆点】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=106 这道题还真是完全没思路,真的不知道怎么做,但是看了题解后恍然大悟. ...

  6. USACO翻译:USACO 2012 JAN三题(2)

    USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...

  7. USACO翻译:USACO 2012 JAN三题(1)

    USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...

  8. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  9. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

随机推荐

  1. 为什么要使用动态链接库(DLL)

    为什么要使用动态链接库(DLL)   第一章 为什么要使用动态链接库(DLL) top 提起DLL您一定不会陌生,在Windows中有着大量的以DLL为后缀的文件,它们是保证Windows正常运行和维 ...

  2. 使用Sonatype Nexus搭建Maven私服后,如何添加第三方JAR包

    使用Sonatype Nexus搭建Maven私服后如何添加第三方JAR包 步骤如下 1.打开nexus地址,进行登录 2.登录Nexus后,点击右侧的“Repositories”,显示当前Nexus ...

  3. 仿淘宝使用flex布局实现页面顶部和底部的固定布局

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  4. NX二次开发-UFUN遍历函数UF_OBJ_cycle_all

    NX11+VS2013 #include <uf.h> #include <uf_obj.h> #include <uf_modl.h> #include < ...

  5. Go将统治下一个10年?Go语言发展现状分析

    “本文是国内Go语言大中华区首席布道师——许式伟,在QCon2015上海站上的分享.他预测Go语言10年内一定会超过C和java,并且统治这一个10年. Go语言语法及标准库变化 Go从1.0版本到现 ...

  6. flutter 动态申请权限

    https://pub.flutter-io.cn/packages/permission_handler https://www.jianshu.com/p/fa68876fbdfd 例 Futur ...

  7. DXP 快捷键

    EC 复制 EY array paste TU: update

  8. IntelliJ IDEA无法创建springboot项目解决办法

    最佳解决办法:IntelliJ IDEA---右键---以管理员身份运行. 方法二: 1.打开控制面板--系统和安全--windows防火墙 2.找到自己的默认浏览器,打勾,这里是谷歌浏览器 3.打开 ...

  9. vue点击跳转拨号界面

    <a :href="'tel:' + VipInfo.HotelPhone" style="text-decoration:none;color:black;opa ...

  10. centos yum install 找不到软件包

    yum install epel-release 然后再试试yum install 其他安装包