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. Linux-git安装

    基本操作 安装yum install git 生成SSH KEY :先cd ~/.ssh,在这个目录下输入ssh-keygen,一直回车就可以了,这个时候就会出现id_rsd.pub公钥和id_rsa ...

  2. centos7安装mongodb3.6

    1. 安装一下centos(6.5) + 虚拟机,在VMware中安装mongodb 2. 下载mongodb最新版本:mongodb-linux-x86_64-3.6.4.tgz,传到centos ...

  3. JavaScriptDate(日期)

    如何使用Date()方法获取当日的日期. getFullYear(): 使用getFullYear()获取年份. getTime(): getTime()返回1970年1月1日至今的毫秒数. setF ...

  4. ZendFramework-2.4 源代码 - 关于MVC - Model层类图

  5. Codeforces Round #496 (Div. 3) ABCDE1

    //B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> ...

  6. COGS:313. [POI2001] 和平委员会

    313. [POI2001] 和平委员会 ★★☆   输入文件:spo.in   输出文件:spo.out   评测插件时间限制:1 s   内存限制:128 MB 题目描述 根据宪法,Bytelan ...

  7. Springmvc 重定向参数传递方式

    Springmvc  通过return "redirect:" 实现重定向   重定向的状态码301  302 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移 ...

  8. Asp.net自定义控件开发任我行(2)-TagPrefix标签

    摘要 前面我们已经做了一个最简单的TextBox的马甲,此篇文章,我们来讲讲自定义控件的标签.大家可能看到了上一篇中拖放进来的代码是 <cc1:TextEdit ID="TextEdi ...

  9. Robotium接入到Jenkins持续集成自动化测试

    6.3 将测试用例接入到Jenkins 由于我是自己学习的手机自动化测试,没有实际投入到工作中使用,jenkins的接入也没有具体操作,现摘抄一下网页:http://www.tuicool.com/a ...

  10. 《HTTP协议详解》读书笔记---请求篇之响应状态码

    在接收和解释请求消息后,服务器返回一个http响应消息.它也分为3个部分:状态行.消息报头.响应正文,格式如下: HTTP-VersionStatus-CodeReason-PhraseCRLF(CR ...