Construct

【问题描述】

随着改革开放的深入推进…… 小T家要拆迁了…… 当对未来生活充满美好憧憬的小T看到拆迁协议书的时候,小T从一位大好的社会主义青年变成了绝望的钉子户。 由于小T的家位于市中心,拆迁工作又难以进行,有关部门决定先把小T家用围栏围起来,以免影响市容。考虑到要建设资源节约型社会,他们希望所用的围栏长度越短越好,由于市中心寸土寸金,在围栏长度最短的情况下,围出的多边形面积越小越好。 为了简化问题,我们约定,小T的家是一个多边形,并且每条边与坐标轴平行,围栏构成的也是多边形,每条边与坐标轴平行。

【输入格式】

在第一行列出整数n——多边形的顶点的数量。在以下n行中的每一行都有两个整数——沿逆时针方向走过这个多边形顺次所经过的顶点的坐标。边界的任意三个连续顶点不在一条直线上。多边形的边界不含自交和自切。

【输出格式】

输出两行,第一行为围栏最短的长度,第二行为长度最短的前提下,最小的面积。

【样例输入】

8
0 0
9 0
9 9
6 9
6 3
3 3
3 6
0 6

【样例输出】

36
63


【数据范围】

对于100%的数据4≤n≤100000,坐标的绝对值不超过109 。


题解:

题意就是求直的凸包

那么我们把这个凸包分成左上、左下、右上、右下

把点按横坐标排下序

每一部分的纵坐标单调递增或者单调递减

用单调栈维护就好了

 #include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long lar;
const int maxn = 2e5 + ;
const lar inf = 2e9;
int n;
int top;
int num;
lar ans;
struct point
{
lar x, y;
inline void print()
{
printf("%lld %lld\n", x, y);
}
friend inline lar operator * (point a, point b)
{
return a.x * b.y - a.y * b.x;
}
};
point mi, ma;
point p[maxn];
point s[maxn];
inline bool hor(point a, point b)
{
return (a.x != b.x) ? a.x < b.x : a.y < b.y;
}
inline void Scan(int &x)
{
char c;
bool o = false;
while(!isdigit(c = getchar())) o = (c != '-') ? o : true;
x = c - '';
while(isdigit(c = getchar())) x = x * + c - '';
if(o) x = -x;
}
inline void Max(point &a, point b)
{
a.x = max(a.x, b.x);
a.y = max(a.y, b.y);
}
inline void Min(point &a, point b)
{
a.x = min(a.x, b.x);
a.y = min
(a.y, b.y);
}
int main()
{
Scan(n);
int x, y;
for(int i = ; i <= n; ++i)
{
Scan(x), Scan(y);
p[i] = (point) {x, y};
}
sort(p + , p + + n, hor);
int up, be;
point mi, ma;
mi.x = mi.y = inf;
ma.x = ma.y = -inf;
for(int i = ; i <= n; ++i)
{
Max(ma, p[i]);
Min(mi, p[i]);
}
int now = ;
while(now <= n)
{
if(!top || p[now].y >= s[top].y) s[++top] = p[now];
if(p[now++].y == ma.y) break;
}
while(now <= n)
{
while(p[now].y > s[top].y) --top;
s[++top] = p[now++];
}
for(int i = ; i < top; ++i) ans += min(s[i + ].y, s[i].y) * (s[i + ].x - s[i].x);
top = ;
now = ;
while(now <= n)
{
if(!top || p[now].y <= s[top].y) s[++top] = p[now];
if(p[now++].y == mi.y) break;
}
while(now <= n)
{
while(p[now].y < s[top].y) --top;
s[++top] = p[now++];
}
for(int i = ; i < top; ++i) ans -= max(s[i + ].y, s[i].y) * (s[i + ].x - s[i].x);
lar one = (ma.x + ma.y - mi.x - mi.y) << ;
printf("%lld\n%lld", one, ans);
}

BZOJ 2146 Construct的更多相关文章

  1. bzoj AC倒序

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

  2. [LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅

    [LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅 题意 比较复杂放LOJ题面好了qaq... Kiana 最近喜欢到一家非常美味的寿司餐厅用餐. 每天晚上,这家餐厅都会按顺序提供 ...

  3. BZOJ 1006 [HNOI2008] 神奇的国度(简单弦图的染色)

    题目大意 K 国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即 AB 相互认识,BC 相互认识,CA 相互认识,是简洁高效的.为了巩固三角关系,K 国禁止四边关系,五边关系等 ...

  4. BZOJ 2127: happiness [最小割]

    2127: happiness Time Limit: 51 Sec  Memory Limit: 259 MBSubmit: 1815  Solved: 878[Submit][Status][Di ...

  5. Leetcode, construct binary tree from inorder and post order traversal

    Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs ab ...

  6. [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  7. [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  8. BZOJ 3275: Number

    3275: Number Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 874  Solved: 371[Submit][Status][Discus ...

  9. BZOJ 2879: [Noi2012]美食节

    2879: [Noi2012]美食节 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1834  Solved: 969[Submit][Status] ...

随机推荐

  1. 【C++学习笔记】强大的算法——spfa

    spfa的定义 PFA算法的全称是:Shortest Path Faster Algorithm,用于求单源最短路,由西南交通大学段凡丁于1994年发表.当给定的图存在负边时,Dijkstra算法就无 ...

  2. 线程池是什么?Java四种线程池的使用介绍

    使用线程池的好处有很多,比如节省系统资源的开销,节省创建和销毁线程的时间等,当我们需要处理的任务较多时,就可以使用线程池,可能还有很多用户不知道Java线程池如何使用?下面小编给大家分享Java四种线 ...

  3. find cat sed awk 简单组合使用

    find:查找 // .表示当前目录:   /表示根目录:  | 管道符:  xargs表示将前面的搜索接口作为参数传递到后面的命令中:grep 过滤 // xxxx表示文件名 1.查找指定文件名的文 ...

  4. hashlib模块常用功能

    什么是hash hash是一种算法,该算法接受传入的内容,经过运算得到一串hash值 如果把hash算法比喻为一座工厂 那传给hash算法的内容就是原材料 生成的hash值就是生产出的产品 2.为何要 ...

  5. wusir 面试题答案在老男孩的视频里

    注意:你问答案在哪里?答案在视频里了,就是不给你写. 第一部分 Python基础篇(80题) 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C#.C+ ...

  6. MTCNN自己的学习理解

    MTCNN 流程 经过三个网络 P-Net,R-Net,O-Net 对于P-Net: P-Net是一个全卷积层,不涉及到全连接层,所以我们的输入图像的尺寸可以是不固定的. 对于P-Net来说,我们的输 ...

  7. VScode的settings.json配置

    { "editor.mouseWheelZoom": true, "astyle.additional_languages": [ "c", ...

  8. RCP 主题切换

    第一步 编写css文件,放到项目目录下 第二步 添加切换主题扩展点 第三步 设置主题   public  void switchTheme(String themeID) {           Bu ...

  9. ogre3D,cegui配置问题

    今天按照网上的教程配置CEGUI, 一直运行不了,不明白原因,而后又出现了错误 LNK1104: 无法打开文件“OgreGUIRenderer_d.lib”,经过反复检查,排除包含目录问题. 不过可能 ...

  10. Swift全栈开发

    前段时间学习了一下Swift web framework-Vapor, 类似于PHP Laravel的web框架. Apple也成立了Server APIs Project, Server-side ...