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 ...
随机推荐
- poj 3254 Corn Field
Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; ...
- NX二次开发-UFUN多按钮模态对话框UF_UI_message_dialog
NX11+VS2013 #include <uf.h> #include <uf_ui.h> UF_initialize(); //多按钮模态对话框 ; char title_ ...
- 移动端多选插件-jquery
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- MPU-6000 与 MPU-6050
VLOGIC 是什么呢?
- 2014 0416 word清楚项目黑点 输入矩阵 普通继承和虚继承 函数指针实现多态 强弱类型语言
1.word 如何清除项目黑点 选中文字区域,选择开始->样式->全部清除 2.公式编辑器输入矩阵 先输入方括号,接着选择格式->中间对齐,然后点下面红色框里的东西,组后输入数据 ...
- Deep Dive into Neo4j 3.5 Full Text Search
In this blog we will go over the Full Text Search capabilities available in the latest major release ...
- 1.springboot+ActiveMQ
1.项目结构如下 pom.xml文件如下 <dependencies> <dependency> <groupId>junit</groupId> &l ...
- MySQL更新指定分组中最大值记录
数据表中存储着某个状态字段,当分组中所有数据入库后,需要根据相应的最大值更新状态字段,如表: 现在要将no=11的分组中把最大值记录的status更新为1,可以直接这么写: ; done~
- protobuf文档翻译-安装,数据格式及编码规范
Install Download protobuf: https://github.com/protocolbuffers/protobuf/releases unzip protoc-3.8.0-l ...
- 查看ubuntu系统的版本信息
显示如下 Linux version 4.10.0-28-generic (buildd@lgw01-12) linux内核版本号 gcc version 5.4.0 20160609 gcc编译器版 ...