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] ...
随机推荐
- Mysql之1451 - Cannot delete or update a parent row: a foreign key constraint fails...解决办法记录
今天使用delete语句删除一张表中的一条信息时,提示了这么一个错误:1451 - Cannot delete or update a parent row: a foreign key constr ...
- ELK详细安装部署
一.前言 日志主要包括系统日志和应用程序日志,运维和开发人员可以通过日志了解服务器中软硬件的信息,检查应用程序或系统的故障,了解故障出现的原因,以便解决问题.分析日志可以更清楚的了解服务器的状态和 ...
- bootstrap-图片样式记录
//三种形状<img src=”img/pic.png” alt=”图片” class=”img-rounded” /><img src=”img/pic.png” alt=”图片” ...
- Python中的set
set_lst = [ ('集合容器不可哈希',), ('集合中的元素必须可哈希',), ('集合是无序的',), ('集合自动去重',), ('增',), ('删',), ('查',), ('集合运 ...
- May I see you again?【我可以再见到你吗?】
May I see you again "May I see you again?" he asked. There was an endearing nervousness in ...
- 动态规划:完全背包问题-HDU1114-Piggy-Bank
解题心得: 1.这是一个完全背包问题的变形,题目要求是求在规定的重量下求价值最小,所以需要将d[0]=0关键的初始化 2.当不可能出现最小的价值时,d的状态并没有被改变,说明并没有放进去一个硬币. 题 ...
- CSU-2007 Football Training Camp
Football Training Camp 在一次足球联合训练中一共有n支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为平局则两支队伍各得1分. Input 输 ...
- Python框架之Django学习笔记(二)
安装Django 我是在windows下安装的python以及django,下面的链接可以下载Django: http://www.djangoproject.com/download/ 1.下载 D ...
- Bug的类型
美国计算机科学家.图灵奖获得者詹姆斯·尼古拉·格雷(Jim Gray),在他的著名的论文“Why do computers stop and what can be done about it?”中首 ...
- MFC定时关机程序的实现2-添加启动项到注册表
虽然上一篇实现了的定时关机,但是还不够完善,比如开机自动启动,然后按照配置的时间定时关机,并最小化到任务栏. 先来说开机启动怎么实现,开机启动实现的方法有好几种,比如直接在开始菜单启动项里添加一个程序 ...