BZOJ 2146 Construct
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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅
[LOJ 2146][BZOJ 4873][Shoi2017]寿司餐厅 题意 比较复杂放LOJ题面好了qaq... Kiana 最近喜欢到一家非常美味的寿司餐厅用餐. 每天晚上,这家餐厅都会按顺序提供 ...
- BZOJ 1006 [HNOI2008] 神奇的国度(简单弦图的染色)
题目大意 K 国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即 AB 相互认识,BC 相互认识,CA 相互认识,是简洁高效的.为了巩固三角关系,K 国禁止四边关系,五边关系等 ...
- BZOJ 2127: happiness [最小割]
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
- 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 ...
- [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 ...
- [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 ...
- BZOJ 3275: Number
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
- BZOJ 2879: [Noi2012]美食节
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
随机推荐
- 通过LDB_PROCESS函数使用逻辑数据库
1.概览 通过LDB_PROCESS函数可以允许任何程序访问逻辑数据库,允许一个程序访问多个逻辑数据库,当然也允许多次连续访问访问同个逻辑数据库.当使用LDB_PROCESS函数来访问逻辑数据库 ...
- gravity 使用操作。
gravity 使用操作.最近我司有一个比较奇葩的需求,我们的环境是主从,因为数据量较大会定期的删除数据,最近不行了,要求新建出来一个库 同步正事环境的数据,但是要剔除 delete ,drop,tr ...
- PHP namespace、abstract、interface、trait使用介绍
小菜鸟一枚,一直搞不懂 namespace.abstract.interface.trait 这些关系,就抽出几天时间研究,做个总结,不足之处希望大家指正交流. namespace 命名空间 介绍:顾 ...
- 如何禁止用户连续点击一个按钮事件详细JS
<input type="button" id="submit" value="提交"> <script> $(do ...
- EventUtil处理js兼容性问题
var EventUtil={ addHandler:function(element,type,handler){ //添加事件 if(element.addEventListener){ elem ...
- 谭浩强C第四版(p141)16.输出以下图案
运行结果: * *** ***** ******* ***** *** * Press any key to continue #include<stdio.h> int main() { ...
- java十分钟速懂知识点——引用
一.由健忘症引起的问题 今天闲来没事在日志中瞟见了个OutOfMemoryError错误,不由得想到前一段时间看到一篇面经里问到Java中是否有内存泄露,这个很久以前是留意过的,大体记得内存溢出和内存 ...
- Unity 与Mono和.Net的关系
一.分析 首先,我们要知道Unity,Mono,.Net 三者的关系.需要简单说一下.Net. .Net拥有跨语言,跨平台性. 跨语言:就是只要是面向.Net平台的编程语言,用其中一种语言编写的类型就 ...
- ogre3D学习基础5 -- 阴影与动画
五.阴影 阴影是渲染一个真实场景的重要组成部分,它可以给场景中的物体提供更加真实的感觉,同时还可以帮助用户更好的了解对象间的空间关系. 启用阴影: 缺省情况下,阴影是关闭的,开启方式如下: 1.建立场 ...
- Android坐标getLeft,getRight,getTop,getBottom,getLocationInWindow和getLocationOnScreen
Android中获取坐标点的一些方法解释 一.getLocationInWindow和getLocationOnScreen的区别 // location [0]--->x坐标,location ...