题目描述

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


输入格式

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


输出格式

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


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

  • 题解

    • 可能和凸包没有什么关系吧。。。。。
    • 周长显然,直接将所有框起来即可,$2 * (max \{ x_{i} \}  -  min\{ x_{i} \} \ \  + \ \  max \{ y_{i} \}  -  min\{ y_{i} \}) $
    • 将所有都框起来并不是面积最小,因为有些部分收进去周长不会边长,但是面积会减小;
    • 但是也不能全部收进去因为会有类似于“凹”字的形状收进去后周长会变大;
    • 考虑每次从上到下扫描,维护当前横坐标的最大值和最小值,如果更新了最大值或最小值就新建一个拐点和新点;
    • 再从下面来一次,直接得到了点数O(2*n)的框,求面积即可;
 #include<bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
using namespace std;
const int N = ;
int n,c1,c2,c3,c4;
struct P{
int x,y;
P(int X=,int Y=):x(X),y(Y){};
bool operator <(const P&a)const{return x<a.x;}
}p[N],p1[N],p2[N],p3[N],p4[N];
char gc(){
static char*P1,*P2,s[];
if(P1==P2)P2=(P1=s)+fread(s,,,stdin);
return(P1==P2)?EOF:*P1++;
}
int rd(){
int x=,f=;char c=gc();
while(c<''||c>''){if(c=='-')f=-;c=gc();}
while(c>=''&&c<='')x=x*+c-'',c=gc();
return x*f;
}
ll crs(const P&a,const P&b){return (ll)a.x*b.y-(ll)a.y*b.x;}
int main(){
#ifndef ONLINE_JUDGE
freopen("bzoj2146.in","r",stdin);
freopen("bzoj2146.out","w",stdout);
#endif
n=rd();
for(int i=;i<=n;++i)p[i].x=rd(),p[i].y=rd();
sort(p+,p+n+);
for(int i=,j=,mn=inf,mx=-inf;i<=n;i=j){
int mn1=inf,mx1=-inf;
for(;j<=n&&p[j].x==p[i].x;j++){
mn1=min(mn1,p[j].y);
mx1=max(mx1,p[j].y);
}
if(mn1<mn){
if(mn!=inf)p1[++c1]=P(p[i].x,mn);
p1[++c1]=P(p[i].x,mn=mn1);
}
if(mx1>mx){
if(mx!=-inf)p2[++c2]=P(p[i].x,mx);
p2[++c2]=P(p[i].x,mx=mx1);
}
} for(int i=n,j=n,mn=inf,mx=-inf;i;i=j){
int mn1=inf,mx1=-inf;
for(;j&&p[j].x==p[i].x;j--){
mn1=min(mn1,p[j].y);
mx1=max(mx1,p[j].y);
}
if(mn1<mn){
if(mn!=inf)p3[++c3]=P(p[i].x,mn);
p3[++c3]=P(p[i].x,mn=mn1);
}
if(mx1>mx){
if(mx!=-inf)p4[++c4]=P(p[i].x,mx);
p4[++c4]=P(p[i].x,mx=mx1);
}
}
P lst = p2[];
ll ans1=,ans2=;
for(int i=;i<=c1;++i){
ans1+=abs(p1[i].x-lst.x)+abs(p1[i].y-lst.y);
ans2+=crs(lst,p1[i]);
lst=p1[i];
}
for(int i=c3;i;--i){
ans1+=abs(p3[i].x-lst.x)+abs(p3[i].y-lst.y);
ans2+=crs(lst,p3[i]);
lst=p3[i];
}
for(int i=;i<=c4;++i){
ans1+=abs(p4[i].x-lst.x)+abs(p4[i].y-lst.y);
ans2+=crs(lst,p4[i]);
lst=p4[i];
}
for(int i=c2;i;--i){
ans1+=abs(p2[i].x-lst.x)+abs(p2[i].y-lst.y);
ans2+=crs(lst,p2[i]);
lst=p2[i];
}
printf("%lld\n%lld\n",ans1,ans2>>);
return ;
}

bzoj2146

bzoj2146 Construct的更多相关文章

  1. 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 ...

  2. [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 ...

  3. [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 ...

  4. 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 that ...

  5. 【LeetCode OJ】Construct Binary Tree from Preorder and Inorder Traversal

    Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-trave ...

  6. LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal

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

  7. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  8. Construct Binary Tree from Preorder and Inorder Traversal

    Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...

  9. Reorder array to construct the minimum number

    Construct minimum number by reordering a given non-negative integer array. Arrange them such that th ...

随机推荐

  1. python-模拟掷骰子,两个筛子数据可视化

    """ 作者:zxj 功能:模拟掷骰子,两个筛子数据可视化 版本:3.0 日期:19/3/24 """ import random impo ...

  2. Mysql数据库的隔离级别

    Mysql数据库的隔离级别有四种 1.read umcommitted   读未提交(当前事务可以读取其他事务没提交的数据,会读取到脏数据) 2.read committed 读已提交(当前事务不能读 ...

  3. windows 无法链接 \\ , 拼写错误或者网络有问题,解决方法

    1. 楼主首先在网上搜索了一遍问题, 比较全面的回答链接如下http://blog.csdn.net/newizan/article/details/50313137 然而并没有解决问题, 于是反思了 ...

  4. ES6----Proxy(一)

    Proxy 用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”(meta programming),即对编程语言进行编程. 听起来好像很绕,可以简单这样理解,Proxy相当于 ...

  5. 凡事不求甚解,遇事必定抓瞎——PHP开发Apache服务器配置备忘录

    照此配置流程,绝对一路畅通,可保无虞. 昨天弄了个PHP小程序,想在本地跑一下测试,可是工作电脑没有安装环境,于是下载了一个wamp,一路畅通,Apache.Mysql.PHP就全有了.启动wamp服 ...

  6. Final发布用户使用报告 -- Thunder团队

    Thunder爱阅app Final发布用户使用报告 用户数量:14人 以下为用户评论:(注:为了保护用户的姓名权,以下用户名以昵称形式给出.) 序列 昵称 个人信息 获得软件途径 使用次数 用户评论 ...

  7. Java& Vector与ArrayList区别

    在写java的时候,基本上都喜欢用arraylist,甚至我都不知道有个vector的存在.查了一下发现又是线程安全问题...咋个线程安全天天围着我转呢...多得阿里巴巴,让我开始认识java的所谓线 ...

  8. Windows上MyEclipse2017 CI7 安装、破解以及配置

    一.安装环境与安装包 操作系统:win7 MyEclipse2017 CI7下载地址:链接:https://pan.baidu.com/s/1TWkwntF9i5lOys3Z96mpLQ MyEcli ...

  9. 微信小程序 功能函数 定时震动

    ffn: function () { let nnn = this.data.nnn nnn += 1; this.setData({ nnn: nnn }); if (nnn > 10) { ...

  10. MySql的多存储引擎架构, 默认的引擎InnoDB与 MYISAM的区别(滴滴)

    1.存储引擎是什么? MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择不同的技术, ...