2365: Splitting the Field

题意:n个点,求用两个矩形面积覆盖完所有点和一个矩形覆盖完少多少面积

思路:枚举两个矩形的分割线,也就是把所有点分成两个部分,枚举分割点;先预处理每个点之前和之后的最大,最低高度;

矩形可以横着分,也可以竖着分

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
struct point{
int x,y;
point(int x_=,int y_=):x(x_),y(y_){}
bool operator < (const point &a) const{
return x==a.x?y<a.y:x<a.x;
}
}p[N];
int l[N],r[N],l1[N],r1[N];
int n;
LL ans;
void work(){
clc(l,inf),clc(r,-inf),clc(l1,inf),clc(r1,-inf);
sort(p+,p+n+);
for(int i=;i<=n;i++){
l[i]=min(l[i-],p[i].y),r[i]=max(r[i-],p[i].y);
}
for(int i=n;i>=;i--){
l1[i]=min(l1[i+],p[i].y),r1[i]=max(r1[i+],p[i].y);
}
for(int i=;i<=n;i++){
LL tem=(LL)(r[i-]-l[i-])*(p[i-].x-p[].x)+(LL)(r1[i]-l1[i])*(p[n].x-p[i].x);
ans=min(tem,ans);
}
}
int main(){
int minx=inf,miny=inf,maxx=-inf,maxy=-inf;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
minx=min(minx,p[i].x);
maxx=max(maxx,p[i].x);
miny=min(miny,p[i].y);
maxy=max(maxy,p[i].y);
}
ans=(LL)(maxx-minx)*(maxy-miny);
LL ans1=ans;
work();
for(int i=;i<=n;i++) swap(p[i].x,p[i].y);
work();
printf("%lld\n",ans1-ans);
return ;
}

bzoj4578: [Usaco2016 OPen]Splitting the Field的更多相关文章

  1. 洛谷P3145 [USACO16OPEN]分割田地Splitting the Field

    P3145 [USACO16OPEN]分割田地Splitting the Field 题目描述 Farmer John's NN cows (3 \leq N \leq 50,0003≤N≤50,00 ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. USACO比赛题泛刷

    随时可能弃坑. 因为不知道最近要刷啥所以就决定刷下usaco. 优先级排在学习新算法和打比赛之后. 仅有一句话题解.难一点的可能有代码. 优先级是Gold>Silver.Platinum刷不动. ...

  4. USACO 2016 US Open Contest, Gold解题报告

    1.Splitting the Field http://usaco.org/index.php?page=viewproblem2&cpid=645 给二维坐标系中的n个点,求ans=用一个 ...

  5. US Open 2016 Contest

    比较弱,只写了金组和银组,铂金组的第一题. [262144] http://www.usaco.org/index.php?page=viewproblem2&cpid=648 给一个序列,相 ...

  6. 【BZOJ 4581】【Usaco2016 Open】Field Reduction

    http://www.lydsy.com/JudgeOnline/problem.php?id=4581 考虑\(O(n^3)\)暴力. 实际上枚举最靠边的三个点就可以了,最多有12个点. 还是暴力= ...

  7. BZOJ 4581: [Usaco2016 Open]Field Reduction

    Description 有 \(n\) 个点,删掉三个点后,求最小能围住的面积. Sol 搜索. 找出 左边/右边/上边/下边 的几个点枚举就可以了. 我找了 12 个点,统计一下坐标的个数,然后找到 ...

  8. 关于 Word Splitting 和 IFS 的三个细节

    在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...

  9. salesforce 零基础学习(六十二)获取sObject中类型为Picklist的field values(含record type)

    本篇引用以下三个链接: http://www.tgerm.com/2012/01/recordtype-specific-picklist-values.html?m=1 https://github ...

随机推荐

  1. s3cmd的安装与使用

     s3cmd 是一款 Amazon S3 命令行工具.它不仅能上传.下载.同步,还能设置权限,下面是完整的安装使用指南. 主要是还是用来储存日志文件或者其他什么资料. https://wangyan. ...

  2. MVVM 代码记录

      一.XML <Page x:Class="MVVM.MainPage" xmlns="http://schemas.microsoft.com/winfx/20 ...

  3. 如何在Android应用程序中使用传感器模拟器SensorSimulator

    原文地址; 如何在Android应用程序中使用传感器模拟器 - 移动平台应用软件开发技术 - 博客频道 - CSDN.NET http://blog.csdn.net/pku_android/arti ...

  4. PHP裁剪图片

    PHP裁剪图片 $src_path = '1.jpg'; //创建源图的实例 $src = imagecreatefromstring(file_get_contents($src_path)); / ...

  5. 编写自己的TRACE函数

    TRACE函数是MFC里面的一个宏,是对OutputDebugString的封装. OutputDebugString的作用是输出调试信息,不要以为这个函数只有在Debug版本才会打日志,即使是Rel ...

  6. 利用qt打开一张图片并转成灰度矩阵

    首先是mat类,这个类的主要作用是构造一个容器,并将对应像素的灰度值放在容器内 #ifndef MAT_H #define MAT_H #include <vector> #include ...

  7. Java API —— JDK5新特性

    JDK5新特性         自动拆装箱.泛型.增强for.静态导入.可变参数.枚举   1.增强for概述         1)简化数组和Collection集合的遍历         2)格式: ...

  8. ios高版本SDK在低版本真机调试

    将build settings的ios deployment target改为对应真机系统版本即可

  9. ubuntu下android源码下载

    步骤一: 首先保证你的ubuntu系统电脑可以顺利游览google,我们是将etc下 hosts替换掉,推荐hosts: http://laod.cn/hosts/2015-google...host ...

  10. javascript算法汇总(持续更新中)

    1. 线性查找 <!doctype html> <html lang="en"> <head> <meta charset="U ...