Points

题目链接:

http://acm.hust.edu.cn/vjudge/contest/130303#problem/E

Description


http://7xjob4.com1.z0.glb.clouddn.com/4c9abc79e61f4d543441b48cb0cf6bbe

Input


The input file contains several test cases, each of them as described below.
The first line contains integer N — the number of points placed by Peter (1 ≤ N ≤ 100000). Each of
following N lines contains two integers xi , yi — the point coordinates placed by Peter. The coordinates by absolute value do not exceed 10^6 . Some points can match.

Output


For each test case, you need to print one number — the perimeter of the required polygon, on a line
by itself. The answer should be printed with accuracy not less than 0.001.

Sample Input


```
1
0 0
2
1 1
1 2
```

Sample Output


```
5.656
7.656854
```

Source


2016-HUST-线下组队赛-4


##题意:

给出网格上的n个点,求一个周长最小的多边形使得所有点都在其内部,且多边形的边要么是网格的边,要么是网格的对角线.


##题解:

由于边只能是网格边或者对角线,在纸上画一下三角形时的情况即可推出结果轮廓.
先对所有点求一个凸包,然后把凸包拓展成为由网格边或对角线组成的多边形,再整体往外扩大1即是最后的结果.


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define maxn 111000
#define inf 0x3f3f3f3f
#define mod 1000000007
#define mid(a,b) ((a+b)>>1)
#define eps 1e-8
#define IN freopen("in.txt","r",stdin);
using namespace std;

int n;

struct Point{

LL x,y;

Point() {}

Point(LL tx, LL ty) {x=tx;y=ty;}

}p[maxn];

LL xmul(Point p0, Point p1, Point p2) {

return (p1.x-p0.x)(p2.y-p0.y) - (p2.x-p0.x)(p1.y-p0.y);

}

LL Dis(Point p1, Point p2) {

return (p1.x-p2.x)(p1.x-p2.x) + (p1.y-p2.y)(p1.y-p2.y);

}

int s[maxn], top;

int cmp_polar(Point p1, Point p2) {

LL tmp = xmul(p[0], p1, p2);

if(tmp > 0) return 1;

else if(tmp==0 && (Dis(p[0],p1)-Dis(p[0],p2))<0) return 1;

else return 0;

}

void polar(int n) {

int pos = 0;

Point p0 = p[0];

for(int i=1; i<n; i++) {

if(p0.y>p[i].y || (p0.y==p[i].y && p0.x>p[i].x)) {

p0 = p[i];

pos = i;

}

}

p[pos] = p[0];

p[0] = p0;

sort(p+1, p+n, cmp_polar);

}

void Gramham(int n) {

polar(n);

top = 0;
for(int i=0; i<n; i++) {
while(top>1 && xmul(p[s[top-2]],p[s[top-1]],p[i])<=0) top--;
s[top++] = i;
}

}

int main()

{

//IN;

while (scanf("%d", &n) != EOF)
{
for(int i=0; i<n; i++) {
scanf("%I64d %I64d", &p[i].x, &p[i].y);
} Gramham(n); LL ans1 = 0, ans2 = 0;
for(int i=0; i<top; i++) {
Point p1, p2;
p1 = p[s[i]];
if(i<top-1) p2 = p[s[i+1]];
else p2 = p[s[0]]; LL dx = abs(p1.x - p2.x);
LL dy = abs(p1.y - p2.y);
ans1 += abs(dx - dy);
ans2 += min(dx, dy);
} ans2 += 4;
double ans = 1.0*ans1 + sqrt(2.0)*(double)ans2; printf("%f\n", ans);
} return 0;

}

UVALive 6859 Points (凸包)的更多相关文章

  1. UVaLive 6859 Points (几何,凸包)

    题意:给定 n 个点,让你用最长的周长把它们严格包围起来,边长只能用小格子边长或者是小格子对角线. 析:先把每个点的上下左右都放到一个集合中,然后求出一个凸包,然后先边长转成题目的方式,也好转两个点的 ...

  2. UVALive 6859——凸包&&周长

    题目 链接 题意:在一个网格图上,给出$n$个点的坐标,用一个多边形包围这些点(不能接触,且多边形的边只能是对角线或直线),求多边形的最小周长. 分析 对于每个点,我们考虑与之相邻的4个点.一共由 $ ...

  3. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  4. zbar解析二维码demo

    开发环境;ubuntu 18.04 IDE:clion 2019 源文件.cpp #include <opencv2/opencv.hpp> #include <zbar.h> ...

  5. UVALive 4639 && SPOJ SPOINTS && POJ 3805 && AOJ 1298 Separate Points 求两个凸包是否相交 难度:3

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. UVALive 7281 Saint John Festival (凸包+O(logn)判断点在凸多边形内)

    Saint John Festival 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/J Description Porto's ...

  7. POJ 3805 Separate Points (判断凸包相交)

    题目链接:POJ 3805 Problem Description Numbers of black and white points are placed on a plane. Let's ima ...

  8. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...

  9. UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)

    一个n个点的凸多边形,求多边形中离多边形边界最远的距离.实际上就是求凸包最大内接圆的半径. 利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的 ...

随机推荐

  1. java程序启动脚本

    #!/bin/bash appName=`ls|grep .jar$` if [ -z $appName ] then echo "Please check that this script ...

  2. [Web 前端] 032 vue 初识

    目录 0. 先下载 1. 先写个轮廓 2. 牛刀小试 2.1 例子 1 2.2 例子 2 3. 模板语法 上例子 4. 文本指令 上例子 5. 属性操作 上例子 6. 样式操作 上例子 类名的操作 s ...

  3. 遍历文件夹下的csv,把数据读进一张表

    import pandas as pd import os if __name__ == '__main__': Path = 'c:\checklog' dfs = [] for dir_path, ...

  4. SSM框架中数据库无法连接的问题

    首先是SSM框架中所有的配置都是没有问题的,而且项目在其他人的环境上也能正常访问数据库:那么最有可能的就是数据库版本的问题导致数据库连接不上,服务器给我的报错是: 15:37:25.902 [C3P0 ...

  5. PY 个板子计划【雾

    各类板子计划 A+B √ 放个鬼的链接[雾 欧拉筛 √ https://www.cnblogs.com/Judge/p/11690114.html 树状数组 √ 惨痛的教训,以后咱打数据结构的时候绝对 ...

  6. 剑指offer-二叉树的下一结点-树-python

    题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针.   思路:中序遍历,pNode节点的下一个节点根据中序 ...

  7. JavaEE高级-Spring Data学习笔记

    Spring Data概述 - Spring Data : Spring 的一个子项目.用于简化数据库访问,支持NoSQL 和 关系数据存储.其主要目标是使数据库的访问变得方便快捷. - Spring ...

  8. PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)

    科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...

  9. SpringCloude学习脑图

    SpringCloude学习脑图 http://naotu.baidu.com/file/3e619862813ac331c5d9806486771b42?token=1a7206b777280c6b

  10. Qt带参数的信号和槽

    在Qt的开发过程中,信号带参数是很常见的,在使用带参数的信号槽时,有以下几点需要注意. 当信号和槽函数的参数数量相同时,它们的参数类型要完全一致. 信号和槽函数的声明: signals: void i ...