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. thinkphp 3.2.3 - Think.class.php 解析

    class Think { public static function start() { // 注册AUTOLOAD方法 spl_autoload_register('Think\Think::a ...

  2. 如何用eclipse运行导入的maven项目

    1.配置jdk系统环境变量.找到安装的jdk的安装目录,新建系统环境变量,变量名为JAVA_HOME(作为一个引用),变量值为该路径. 找到Path,将%JAVA_HOME%/bin; 添加到变量值的 ...

  3. Python知识点入门笔记——特色数据类型(元组)

    元组(tuple)是Python的另一种特色数据类型,元组和列表是相似的,可以存储不同类型的数据,但是元组是不可改变的,创建后就不能做任何修改操作. 创建元组 用逗号隔开的就是元组,但是为了美观和代码 ...

  4. MongDB之各种删除操作

    接口IMongDaoDelete: package com.net.test.mongdb.dao; public interface IMongDaoDelete { public void del ...

  5. MongDB之各种查询操作

    接口IMongDaoFind: package com.net.test.mongdb.dao; public interface IMongDaoFind { public void findUse ...

  6. 解决Uva网站打开慢的问题

    https://blog.csdn.net/richenyunqi/article/details/80990535

  7. P2065 贪心的果农

    P2065 贪心的果农 题目描述 果农的花园里种着N棵果树.收获的季节终于来到了,果农决定,在接下来的M天时间里完成自己的收获工作.他的收获方式极其暴力——他将会将某棵果树砍倒来获取上面的果实.然而如 ...

  8. React-表单操作

    用户在表单填入的内容,属于用户跟组件的互动,所以不能用 this.props 读取 <!DOCTYPE html> <html lang="zh-cn"> ...

  9. loj2292 「THUSC 2016」成绩单

    ref 我是傻逼,我啥也不会,这是我抄的. #include <iostream> #include <cstring> #include <cstdio> usi ...

  10. python week09 Mysql 数据库基础知识

    第一篇:初识数据库 注:<基础概念,不再赘述,点开链接查看> 第二篇:库相关操作 一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些 ...