博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P3145 [USACO16OPEN]分割田地Splitting the Field
阅读量:5008 次
发布时间:2019-06-12

本文共 2796 字,大约阅读时间需要 9 分钟。

题目描述

Farmer John's NN cows (3 \leq N \leq 50,0003N50,000) are all located at distinct positions in his two-dimensional field. FJ wants to enclose all of the cows with a rectangular fence whose sides are parallel to the x and y axes, and hewants this fence to be as small as possible so that it contains every cow (cowson the boundary are allowed).

FJ is unfortunately on a tight budget due to low milk production last quarter.He would therefore like to enclose a smaller area to reduce maintenance costs,and the only way he can see to do this is by building two enclosures instead of one. Please help him compute how much less area he needs to enclose, in total,by using two enclosures instead of one. Like the original enclosure, the two enclosures must collectively contain all the cows (with cows on boundaries allowed), and they must have sides parallel to the x and y axes. The two enclosures are not allowed to overlap -- not even on their boundaries. Note that enclosures of zero area are legal, for example if an enclosure has zero width and/or zero height.在一个二维的牧场中,Farmer John的N(3<=N<=50000)头牛都各占一席。他想用边平行于x轴和y轴的矩形围栏围住所有牛,并且要让围栏尽可能小(牛可以在边界线上)。

不幸地,由于Farmer John的奶牛产量惨淡,导致最后一个季度预算紧张。因此,他希望封闭一个较小的地区来减少维修的费用,他能看到的唯一方法就是修建两个围栏而不是建一个。请编程告诉他用两个围栏比用一个围栏总共能够节省多少需要围住的面积。同样地,用两个围栏的时候必须围住所有的牛(牛同样可以在边界上),边也要平行于x轴和y轴。两个围栏不允许重叠(边界也不能)。注意面积为零是合法的,例如一个围栏有着长度为零的宽或长度为零的长(一条线)。

输入输出格式

输入格式:

 

The first line of input contains NN. The next NN lines each contain two

integers specifying the location of a cow. Cow locations are positive integers

in the range 1 \ldots 1,000,000,00011,000,000,000.

 

输出格式:

 

Write a single integer specifying amount of total area FJ can save by using two

enclosures instead of one.

 

输入输出样例

输入样例#1: 
64 28 101 19 1214 72 3
输出样例#1: 
107
#include
#include
#include
#include
using namespace std;#define maxn 50010#define INF 0x7fffffffint l[maxn],r[maxn],l1[maxn],r1[maxn],n;long long ans;struct node{ int x,y; bool operator < (const node a)const{ if(x==a.x)return y
=1;i--){ l1[i]=min(l1[i+1],p[i].y); r1[i]=max(r1[i+1],p[i].y); } for(int i=2;i<=n;i++){ long long tem=1LL*(r[i-1]-l[i-1])*(p[i-1].x-p[1].x)+1LL*(r1[i]-l1[i])*(p[n].x-p[i].x); ans=min(tem,ans); }}int main(){ int mnx=INF,mny=INF,mxx=-INF,mxy=-INF; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d",&p[i].x,&p[i].y); mnx=min(mnx,p[i].x);mny=min(mny,p[i].y); mxx=max(mxx,p[i].x);mxy=max(mxy,p[i].y); } ans=1LL*(mxx-mnx)*(mxy-mny); long long ans1=ans; work(); for(int i=1;i<=n;i++)swap(p[i].x,p[i].y); work(); cout<

  

转载于:https://www.cnblogs.com/xiongchongwen/p/11156523.html

你可能感兴趣的文章
MyEclipse Workspace编码与网页/编辑器 中文乱码问题
查看>>
c++函数回顾
查看>>
【深度学习最优化方法】
查看>>
弹出框始终保持居中(包括有滚动条和窗体缩放时)
查看>>
C#访问数据库增删查改代码
查看>>
mysql 8小时超时设置
查看>>
安卓真机ADB shell添加slite3命令
查看>>
php中引用&的真正理解-变量引用、函数引用、对象引用
查看>>
关于<form> autocomplete 属性
查看>>
OutOfMemory
查看>>
LeetCode:组合总数III【216】
查看>>
Thinkphp框架回顾(三)之怎么实现平常的sql操作数据库
查看>>
asp.net利用剪切板导出excel
查看>>
ASP.NET Core文件上传与下载(多种上传方式)
查看>>
编译Console程序时,可以指定Main入口函数
查看>>
虚函数的效率问题
查看>>
POJ 1860 Currency Exchange(SPFA 判断有无“正”环)
查看>>
angular6项目中使用scss
查看>>
书籍阅读目录(给愚钝的自己)
查看>>
-[UIKeyboardLayoutStar release]: message sent to deallocated instance
查看>>