题目描述

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


输入格式

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


输出格式

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


  1. 【数据范围】
  2. 对于100%的数据4n100000,坐标的绝对值不超过109

  • 题解

    • 可能和凸包没有什么关系吧。。。。。
    • 周长显然,直接将所有框起来即可,$2 * (max \{ x_{i} \}  -  min\{ x_{i} \} \ \  + \ \  max \{ y_{i} \}  -  min\{ y_{i} \}) $
    • 将所有都框起来并不是面积最小,因为有些部分收进去周长不会边长,但是面积会减小;
    • 但是也不能全部收进去因为会有类似于“凹”字的形状收进去后周长会变大;
    • 考虑每次从上到下扫描,维护当前横坐标的最大值和最小值,如果更新了最大值或最小值就新建一个拐点和新点;
    • 再从下面来一次,直接得到了点数O(2*n)的框,求面积即可;
  1. #include<bits/stdc++.h>
  2. #define inf 0x7fffffff
  3. #define ll long long
  4. using namespace std;
  5. const int N = ;
  6. int n,c1,c2,c3,c4;
  7. struct P{
  8. int x,y;
  9. P(int X=,int Y=):x(X),y(Y){};
  10. bool operator <(const P&a)const{return x<a.x;}
  11. }p[N],p1[N],p2[N],p3[N],p4[N];
  12. char gc(){
  13. static char*P1,*P2,s[];
  14. if(P1==P2)P2=(P1=s)+fread(s,,,stdin);
  15. return(P1==P2)?EOF:*P1++;
  16. }
  17. int rd(){
  18. int x=,f=;char c=gc();
  19. while(c<''||c>''){if(c=='-')f=-;c=gc();}
  20. while(c>=''&&c<='')x=x*+c-'',c=gc();
  21. return x*f;
  22. }
  23. ll crs(const P&a,const P&b){return (ll)a.x*b.y-(ll)a.y*b.x;}
  24. int main(){
  25. #ifndef ONLINE_JUDGE
  26. freopen("bzoj2146.in","r",stdin);
  27. freopen("bzoj2146.out","w",stdout);
  28. #endif
  29. n=rd();
  30. for(int i=;i<=n;++i)p[i].x=rd(),p[i].y=rd();
  31. sort(p+,p+n+);
  32. for(int i=,j=,mn=inf,mx=-inf;i<=n;i=j){
  33. int mn1=inf,mx1=-inf;
  34. for(;j<=n&&p[j].x==p[i].x;j++){
  35. mn1=min(mn1,p[j].y);
  36. mx1=max(mx1,p[j].y);
  37. }
  38. if(mn1<mn){
  39. if(mn!=inf)p1[++c1]=P(p[i].x,mn);
  40. p1[++c1]=P(p[i].x,mn=mn1);
  41. }
  42. if(mx1>mx){
  43. if(mx!=-inf)p2[++c2]=P(p[i].x,mx);
  44. p2[++c2]=P(p[i].x,mx=mx1);
  45. }
  46. }
  47.  
  48. for(int i=n,j=n,mn=inf,mx=-inf;i;i=j){
  49. int mn1=inf,mx1=-inf;
  50. for(;j&&p[j].x==p[i].x;j--){
  51. mn1=min(mn1,p[j].y);
  52. mx1=max(mx1,p[j].y);
  53. }
  54. if(mn1<mn){
  55. if(mn!=inf)p3[++c3]=P(p[i].x,mn);
  56. p3[++c3]=P(p[i].x,mn=mn1);
  57. }
  58. if(mx1>mx){
  59. if(mx!=-inf)p4[++c4]=P(p[i].x,mx);
  60. p4[++c4]=P(p[i].x,mx=mx1);
  61. }
  62. }
  63. P lst = p2[];
  64. ll ans1=,ans2=;
  65. for(int i=;i<=c1;++i){
  66. ans1+=abs(p1[i].x-lst.x)+abs(p1[i].y-lst.y);
  67. ans2+=crs(lst,p1[i]);
  68. lst=p1[i];
  69. }
  70. for(int i=c3;i;--i){
  71. ans1+=abs(p3[i].x-lst.x)+abs(p3[i].y-lst.y);
  72. ans2+=crs(lst,p3[i]);
  73. lst=p3[i];
  74. }
  75. for(int i=;i<=c4;++i){
  76. ans1+=abs(p4[i].x-lst.x)+abs(p4[i].y-lst.y);
  77. ans2+=crs(lst,p4[i]);
  78. lst=p4[i];
  79. }
  80. for(int i=c2;i;--i){
  81. ans1+=abs(p2[i].x-lst.x)+abs(p2[i].y-lst.y);
  82. ans2+=crs(lst,p2[i]);
  83. lst=p2[i];
  84. }
  85. printf("%lld\n%lld\n",ans1,ans2>>);
  86. return ;
  87. }

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. 02_python内置模块_timeit

    timeit模块可以用来测试一小段python代码的执行速度. (1)timeit.Timer(stmt='pass', setup='pass', timer=<timer function& ...

  2. mkswap命令详解

    基础命令学习目录首页 原文链接:http://blog.51cto.com/arlen99/1743841 mkswap命令用于在一个文件或者设备上建立交换分区.在建立完之后要使用sawpon命令开始 ...

  3. node 集群与稳定

    node集群搭建好之后,还需要考虑一些细节问题. 性能问题 多个工作进程的存活状态管理 工作进程的平滑重启 配置或者静态数据的动态重新载入 其它细节 1 进程事件 Node子进程对象除了send()方 ...

  4. 教你用Python解决非平衡数据问题(附代码)

    本文为你分享数据挖掘中常见的非平衡数据的处理,内容涉及到非平衡数据的解决方案和原理,以及如何使用Python这个强大的工具实现平衡的转换. 后台回复“不平衡”获取数据及代码~ 前言 好久没有更新自己写 ...

  5. [Notice]博客地址转移 vitostack.com

    个人博客地址转移至vitostack.com 这里可能不会经常更新. 欢迎访问新地址.

  6. BugPhobia发布篇章:学霸在线系统正式发布

    Alpha阶段的服务器部署和移植工作最终完成,http://10.2.26.67/,期待您的访问~ 首先,请允许bugphobia团队对您的访问给予感谢以及诚恳的致歉.受服务器端的硬件限制,目前学霸在 ...

  7. Android笔记-3-EditText的属性介绍

    [Android 基础]EditText的属性介绍 EditText继承TextView,所以EditText具有TextView的属性特点,下面主要介绍一些EditText的特有的输入法的属性特点 ...

  8. 第一次spring冲刺第5天

    今天进行讨论基础功能的核心代码方面,还有简单的讨论继续关于界面的美化, 计算生成的答案功能 public class Core {// char[]h={'+','-','*','/'};int re ...

  9. Scala入门系列(二):条件控制与循环

    条件控制与循环   if表达式 定义:if表达式是有值的,就是if或者else中最后一行语句返回的值. 例如:val isAdult = if (age > 18) 1 else 0 类型推断: ...

  10. vSphere Client 连接ESXi 或者是vCenter 时虚拟机提示VMRC异常的解决办法

    1. 自己的vSphere 连接vCenter 向管理虚拟机 结果发现总是有异常. 提示如图示 VMRC控制台的连接已经断开 2. 花了比较长的时间也没搞定. 后来百度发现 关闭一个进程 然后重新登录 ...