http://poj.org/problem?id=1113

题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l

分析  :现在就是求凸包的周长然后再加上一个圆的周长

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue> using namespace std;
#define N 1005
#define pi acos(-1.0)
#define ESP 1e-8 int s[N]; struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
Point operator - (const Point &temp)const
{
return Point(x-temp.x,y-temp.y);
}
Point operator + (const Point &temp)const
{
return Point(x+temp.x,y+temp.y);
}
bool operator == (const Point &temp)const
{
return (x==temp.x && y==temp.y);
}
double operator * (const Point &temp)const
{
return (x*temp.x+y*temp.y);
}
int operator ^ (const Point &temp)const{
double t=x*temp.y-y*temp.x;
if(t>ESP)
return ;
if(fabs(t)<ESP)
return ;
return -;
}
}a[N]; double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} int cmp(Point a1,Point a2)
{
int t=((a1-a[])^(a2-a[]));
if(t==)
return dist(a1,a[])<dist(a2,a[]);
else
return t>;
}
int top;
void Graham(int n)///求凸包
{
s[]=;
s[]=;
top=;
for(int i=;i<n;i++)
{
while(top> && ((a[i]-a[s[top]])^(a[s[top-]]-a[s[top]]))<=)
top--;
s[++top]=i;
} } int main()
{
int n,l;
while(scanf("%d %d",&n,&l)!=EOF)
{
memset(s,,sizeof(s));
int k=;
for(int i=;i<n;i++)
{
scanf("%lf %lf",&a[i].x,&a[i].y);
if(a[i].y<a[k].y || (a[i].y==a[k].y && a[i].x<a[k].x))
k=i;
}
swap(a[],a[k]);
sort(a+,a+n,cmp); Graham(n);
double C=;
for(int i=;i<=top;i++)
{
C+=dist(a[s[i]],a[s[i-]]);
}
C+=dist(a[s[]],a[s[top]]);
C+=*pi*l;
printf("%.0lf\n",C);
}
return ;
}

Wall--POJ1113(极角排序+求凸包)的更多相关文章

  1. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  2. L3-021 神坛(极角排序求三角形最小面积)

    在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面 ...

  3. hdu 1348:Wall(计算几何,求凸包周长)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. Wall - POJ 1113(求凸包)

    题目大意:给N个点,然后要修建一个围墙把所有的点都包裹起来,但是要求围墙距离所有的点的最小距离是L,求出来围墙的长度. 分析:如果没有最小距离这个条件那么很容易看出来是一个凸包,然后在加上一个最小距离 ...

  5. poj 1696 极角排序求最长逆时针螺旋线

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4970   Accepted: 3100 Descrip ...

  6. hdu5785(极角排序求所有锐角钝角个数)

    做法很显然,求出所有的锐角和钝角就能求出有多少个锐角三角形了. 我用了愚钝的方法,写了两三个小时... 看了下别人简单的代码.学习了下做法. sort(temp+,temp+cnt+);//排序 Fo ...

  7. 简单几何(极角排序) POJ 2007 Scrambled Polygon

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

  8. poj 2187:Beauty Contest(计算几何,求凸包,最远点对)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26180   Accepted: 8081 D ...

  9. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

随机推荐

  1. DirectBuffer

    1.如何分配,分配是哪里的内存 ByteBuffer.allocateDirect()来分配(ByteBuffer.allocate()分配堆内内存),分配的是非Heap(堆外)的内存,不排除操作系统 ...

  2. Handler基本概念

    Handler基本概念: Handler主要用于异步消息的处理:当发出一个消息之后,首先进入一个消息队列,发送消息的函数即刻返回,而另外一个部分逐个的在消息队列中将消息取出,然后对消息进行出来,就是发 ...

  3. src与href属性的区别

    src和href之间存在区别,能混淆使用.src用于替换当前元素,href用于在当前文档和引用资源之间确立联系. src是source的缩写,指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在 ...

  4. 面向对于javascript编程

    以构造函数的方式定义对象 function Person(name, age) { this.name = name; this.age = age; this.sayName = function ...

  5. 使用不同用户对Oracle数据库进行异机恢复,失败,错误:Backup file not found in NetBackup catalog

    最近做某数据库恢复演练,数据库版本是10.2.0.4,恢复控制文件一直报错,报错如下,经过反复折腾,原来恢复机上oracle用户不是oracle导致(我的是oraclev4),查看源库oracle用户 ...

  6. Protractor

    官网地址:http://www.protractortest.org/ 1. 预备环境 protractor 是一个 Node.js 程序,为了运行 protractor ,你首先需要 Node 环境 ...

  7. [转]遍历windows服务

    原文:http://www.codeproject.com/Articles/1573/About-Windows-Services #include <windows.h> #inclu ...

  8. [oracle] update和merge语句的几点写法

    1.update t2 set parentid=(select ownerid from t1 where t1.id=t2.id); 2. update tb_client_win_lost_re ...

  9. boost compile

    pushd E:\boost\boost_1_59_0 b2 stage --toolset=msvc-12.0 --without-python --stagedir="E:\boost\ ...

  10. jsp request 对象详解

    转自:http://www.cnblogs.com/qqnnhhbb/archive/2007/10/16/926234.html 1.request对象 客户端的请求信息被封装在request对象中 ...