题目描述

After a long day of work, Farmer John completely forgot that he left his tractor in the middle of the field. His cows, always up to no good, decide to play a prank of Farmer John: they deposit N bales of hay (1 <= N <= 50,000) at various locations in the field, so that Farmer John cannot easily remove the tractor without first removing some of the bales of hay.

The location of the tractor, as well as the locations of the N hay bales, are all points in the 2D plane with integer coordinates in the range 1..1000. There is no hay bale located at the initial position of the tractor. When Farmer John drives his tractor, he can only move it in directions that are parallel to the coordinate axes (north, south, east, and west), and it must move in a sequence of integer amounts. For example, he might move north by 2 units, then east by 3 units. The tractor cannot move onto a point occupied by a hay bale.

Please help Farmer John determine the minimum number of hay bales he needs to remove so that he can free his tractor (that is, so he can drive his tractor to the origin of the 2D plane).

经过一天漫长的工作,农场主 John 完全忘记了他的拖拉机还在场地中央。他的奶牛们总喜欢和他搞些恶作剧,它们在场地的不同位置丢下 N(1 ≤ N ≤ 50,000)堆干草。这样 John 就必须先移走一些干草堆才能将拖拉机开走。

拖拉机和干草堆都可以看作是二维平面上的点,它们的坐标都是整数,坐标范围在 1 到1000 之间。没有那堆干草的坐标和拖拉机的初始坐标一致。John 驾驶拖拉机只能沿着坐标轴的方向移动若干单位长度,比如说,他可以先朝北移动 2 个单位长度,再向东移动 3 个单位长度等等。拖拉机不能移动到干草堆所占据的点。

请你帮助 John 计算一下,最少要移动多少堆干草才能将拖拉机开会坐标原点。

输入输出格式

输入格式:

第一行,三个用空格隔开的整数 N、x、y,表示有N 堆干草和拖拉机的起始坐标。

第 2行到第N+1 行,每行两个用空格隔开的整数 x、y,表示每堆干草的坐标。

输出格式:

一行一个整数,表示最少要移动多少堆干草 John 才能将拖拉机开会坐标原点。

输入输出样例

输入样例#1: 复制

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

输出样例#1: 复制

1 

思路

如果这也叫SPFA的话;

代码

 1 #include<cstdio>
 2 #include<cstring>
 3 const int maxn=1e3+10;
 4 int N,x,y,a,b,c,d;
 5 int s[maxn][maxn];
 6 bool map[maxn][maxn];
 7 int q[maxn*maxn][2],head,tail;
 8 int hb[4]={1,-1,0,0};
 9 int lb[4]={0,0,1,-1};
10 void SPFA(){
11     s[x][y]=0,q[tail][0]=x,q[tail++][1]=y;
12     while(head!=tail){
13         a=q[head][0],b=q[head++][1],head%=maxn*maxn;
14         for(int i=0;i<4;i++){
15             c=a+hb[i],d=b+lb[i];
16             if(c>=0&&c<=1001&&d>=0&&d<=1001)
17             if(s[c][d]>s[a][b]+map[c][d]){
18                 s[c][d]=s[a][b]+map[c][d];
19                 q[tail][0]=c,q[tail++][1]=d,tail%=maxn*maxn;
20             }
21         }
22     }
23 }
24 int main(){
25     scanf("%d%d%d",&N,&x,&y);
26     for(int i=1;i<=N;i++) scanf("%d%d",&a,&b),map[a][b]=1;
27     memset(s,30,sizeof(s));SPFA();
28     printf("%d\n",s[0][0]);
29     return 0;
30 }

转载于:https://www.cnblogs.com/J-william/p/7742960.html

[USACO12MAR]拖拉机相关推荐

  1. 洛谷 P1849 [USACO12MAR]拖拉机Tractor

    题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle ...

  2. [luoguP1849] [USACO12MAR]拖拉机Tractor(spfa)

    传送门 神奇的spfa #include <queue> #include <cstdio> #include <cstring> #include <ios ...

  3. 拖拉机也将自动驾驶,日本劳动力短缺大力发展无人农业

    来源 | HyperAI超神经 责编 | 晋兆雨 头图 | CSDN付费下载自视觉中国 内容提要:为解决农业劳动力短缺问题,日本近年来涌现出自动收割机.插秧机等自动化农业设备.近日,其农机生产商久保田 ...

  4. Java纸牌拖拉机简单模拟

    有天跟前任玩纸牌的拖拉机,来来回回玩了好长时间,分不出胜负,当时就在想,这玩意能分出胜负吗?于是心血来潮就想写一个程序模拟一下,看到底能不能分出胜负,写出来了,能分出胜负,但貌似哪里还有点问题,总共5 ...

  5. 洛谷P2698 [USACO12MAR]花盆Flowerpot

    P2698 [USACO12MAR]花盆Flowerpot 题目描述 Farmer John has been having trouble making his plants grow, and n ...

  6. 中国拖拉机市场情况分析与发展趋势预测分析报告2022-2028年版

    中国拖拉机市场情况分析与发展趋势预测分析报告2022-2028年版   [报告目录]:     第一章 拖拉机相关概述 1.1 拖拉机的基本概念 1.1.1 拖拉机介绍 1.1.2 拖拉机的分类 1. ...

  7. 央视网报道“手机就能打到拖拉机”,网友直呼“想种地了”

    简介:共享拖拉机,减轻农民负担 近日央视网在微博发布了一条新闻[手机就能打到拖拉机!#陕西榆林推出共享拖拉机#],视频一上线,网友纷纷打call"智能化进军农业,想种地了" 据当地 ...

  8. 福州公交车与拖拉机相撞1人死亡

    2007年7月3日下午17时许,福州地区大学新校区学园路路段发生一起交通事故.郑久忠(男,35岁,鼓楼区八一七中路734号弄一号)驾驶41路公交车沿学园路由北往南行驶,途经厚庭路和学园路交叉路口,与林 ...

  9. P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper [模拟退火]

    P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组.(n<=18 ...

最新文章

  1. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:MVC程序中实体框架的连接恢复和命令拦截...
  2. ssh连接卡在【To escape to local shell, press ‘Ctrl+Alt+]‘.】的解决方法
  3. Raspberry Pi 3B 安装NoneBot2
  4. Scala学习之类和属性篇(一):定义类的主构造方法
  5. qhfl-3 Course模块
  6. 在Spring中记录JAX-WS SOAP消息
  7. ActiveMQ死信产生的原因及使用方案
  8. 使用UML工具分析类图与类的关系-bouml(java和C++)
  9. 技术员 Ghost Win 7 Sp1(X86/X64)旗舰加强版201804
  10. 手机通话断了怎么显示链接服务器,手机每次通话三分钟就自动挂断了,怎么回事啊...
  11. ICS工业控制安全类方向赛题简单总结
  12. 模式识别与机器学习(国科大2021-2022秋季学期课程)-基础概念及算法
  13. python用于pmc排产可以吗_有没有免费的PMC生产排程软件啊?
  14. 阿里云相关——VPC阿里云专有网络
  15. 玉米社:百度竞价关键词“否定”与“精确否定”的区别
  16. 【Unity Shader 中Pass相关介绍_第一篇】
  17. 无线路由器打印机服务器设置,newifi新路由打印机服务器设置全教程
  18. VUE的路由器的总结
  19. Redis incr解决并发问题
  20. NYOJ 912 领帽子(全错位排列)

热门文章

  1. 5-510寝室课后习题4.35
  2. Mac下python3配置opencv3 3和Mac下单独opencv的配置以及iOS下配置opencv
  3. 为什么运营商玩不转物联网?
  4. Java Web Model2实战
  5. 一维数组对象转成二维数组
  6. linux 远程禁用root
  7. 浙江大学PAT考试1009~1012(1010上帝是冠军。。)
  8. 英特尔也决定了!正式退出5G智能型手机
  9. 在项目中使用react
  10. Linux 中的虚拟网络