链接

顺便整理出来一份自己看着比较顺眼的模板

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 1010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = 3.141592653;
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {} //构造函数 方便代码编写
}p[N],ch[N];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
pointt operator * (Point a,double b)
{
return Point(a.x*b,a.y*b);
}
pointt operator / (Point a,double b)
{
return Point(a.x/b,a.y/b);
}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
bool operator == (const Point &a,const Point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
//求点积以及利用点积求长度和夹角的函数
double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
}
//叉积及叉积求面积
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double dis(Point a)
{
return sqrt(dot(a,a));
}
double mul(Point p0,Point p1,Point p2)
{
return cross(p1-p0,p2-p0);
}
bool cmp(Point a,Point b)
{
if(dcmp(mul(p[],a,b))==)
return dis(a-p[])<dis(b-p[]);
else
return dcmp(mul(p[],a,b))>;
}
int Graham(int n)
{
int i,k = ,top = ;
Point tmp;
if(n<=)
{
for(i = ; i <= ; i++)
ch[i] = p[i];
return n+;
}
for(i = ; i <= n; i++)
{
if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
k = i;
}
if(k!=)
{
tmp = p[]; p[] = p[k]; p[k] = tmp;
}
sort(p+,p+n+,cmp);
ch[top++] = p[];
ch[top++] = p[];
ch[top++] = p[];
for(i = ; i <= n ;)
{
if(top<||mul(ch[top-],ch[top-],p[i])>)
{
ch[top++] = p[i++];
}
else top--;
}
return top;
}
int main()
{
int i,n,r;
while(scanf("%d%d",&n,&r)!=EOF)
{
for(i = ; i <= n ; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
int top = Graham(n);
ch[top] = p[];
double ma;
ma = *pi*r;
for(i = ; i < top ; i++)
{
ma += dis(ch[i]-ch[i+]);
}
printf("%.0f\n",ma);
}
return ;
}

poj1113Wall(凸包)的更多相关文章

  1. poj1113Wall 求凸包周长 Graham扫描法

    #include<iostream> #include<algorithm> #include<cmath> using namespace std; typede ...

  2. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  3. ZOJ 3871 Convex Hull(计算几何、凸包)

    题意:给n个点,|x[i]|,|y[i]| <= 1e9.求在所有情况下的子集下(子集点数>=3),凸包的面积和. 这题主要有几个方面,一个是凸包的面积,可以直接用线段的有向面积和求得,这 ...

  4. UVALive 2453 Wall (凸包)

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

  5. UVA 11168 Airport(凸包+直线方程)

    题意:给你n[1,10000]个点,求出一条直线,让所有的点都在都在直线的一侧并且到直线的距离总和最小,输出最小平均值(最小值除以点数) 题解:根据题意可以知道任意角度画一条直线(所有点都在一边),然 ...

  6. 关于2016.12.12——T1的反思:凸包的意义与应用

    2016.12.12 T1 给n个圆,保证圆圆相离,求将圆围起来的最小周长.n<=100 就像上图.考场上,我就想用切线的角度来做凸包.以圆心x,y排序,像点凸包一样,不过用两圆之间的下切线角度 ...

  7. poj1228--稳定凸包

    题目大意:给你一个凸包上的某些点(可能在凸包内),询问是否能确定这个凸包. 思路:先求出题目给出的点的凸包,看看在凸包的每条边内(不包括端点)有没有点,若有,则这条边是确定的,若没有,则这条边不确定, ...

  8. POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心

    题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...

  9. HDU 4946 Area of Mushroom(构造凸包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...

随机推荐

  1. 周赛-The Number Off of FFF 分类: 比赛 2015-08-02 09:27 3人阅读 评论(0) 收藏

    The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  2. 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏

    Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...

  3. git: fatal unable to auto-detect email address

    参考:http://stackoverflow.com/questions/25671785/git-fatal-unable-to-auto-detect-email-address 正确使用命令: ...

  4. 操作SQLite的dbhelper

    操作SQLite的dbhelper public class DbHelper { string connStr = @"Data Source=" + System.Enviro ...

  5. phpcms 05

    所谓的异步加载,也就是两个线程同时执行一个任务,比如一个加载文字,一个加载图片,这样子可以先看到文字 footer,html包含尾部文件 {template "content",& ...

  6. 干净的卸载Oracle

    一.在oracle11G以前卸载oracle会存在卸载不干净,导致再次安装失败的情况,在运行services.msc打开服务,停止Oracle的所有服务. 二. oracle11G自带一个卸载批处理\ ...

  7. ie调试工具

    调试ie6真是疯掉了,要到一个包,类firbug,js写的不错. 链接:http://pan.baidu.com/s/1c2JOs0K 密码:fea8

  8. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5883

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 解法:先判断是不是欧拉路,然后枚举 #pragma comment(linker, "/S ...

  9. flask安装

    Flask简介 Flask算是小型框架,自开发伊始就被设计为可扩展的框架,它具有一个包含基本服务的强健核心.Flask有两个依赖:路由.调试.和web服务器网关接口(Web Server Gatewa ...

  10. 2016年10月18日 星期二 --出埃及记 Exodus 19:2

    2016年10月18日 星期二 --出埃及记 Exodus 19:2 After they set out from Rephidim, they entered the Desert of Sina ...