题意:

给n个圆和m个三角形,且保证互不相交,用一个篱笆把他们围起来,求最短的周长是多少。

做法:--水过。。。

把一个圆均匀的切割成500个点,然后求凸包。

注意:求完凸包,在求周长的时候记得要把圆的那部分特殊求。

sin(x)  x=PI*(i/j);//度数表示的时候用PI;

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#define PI 3.1415926
using namespace std;
struct list
{
double x;
double y;
int r;
int pos;
}point[500001],tu[500001],pp;
int tops,num;
int cmp1(struct list a,struct list b)
{
if(a.y!=b.y)return a.y<b.y;
else return a.x<b.x;
}
int cmp2(struct list a,struct list b)
{
if((a.x-point[0].x)*(b.y-point[0].y)==(b.x-point[0].x)*(a.y-point[0].y))
return ((a.x-point[0].x)*(a.x-point[0].x)+(a.y-point[0].y)*(a.y-point[0].y))<((point[0].x-b.x)*(point[0].x-b.x)+(point[0].y-b.y)*(point[0].y-b.y));
return (a.x-point[0].x)*(b.y-point[0].y)>(b.x-point[0].x)*(a.y-point[0].y);
}
int ts;
void yuan(int x,int y,int r)
{
pp.r=r;
for(int i=0;i<500;i++)
{
double du;
du=(double)2.0*PI*i/500.0;
pp.x=1.0*x+1.0*r*cos(du);
pp.y=1.0*y+1.0*r*sin(du);
pp.pos=ts;
point[tops++]=pp;
}
}
int pan(int z,int b,int a)
{
double x1,y1,x2,y2;
if(a<0)return 1;
x1=tu[b].x-tu[a].x;
y1=tu[b].y-tu[a].y;
x2=point[z].x-tu[b].x;
y2=point[z].y-tu[b].y;
if(x1*y2>x2*y1)return 1;
return 0;
}
double len(struct list p1,struct list p2)
{
return (double)sqrt(1.0*((p1.x-p2.x)*(p1.x-p2.x)+1.0*(p1.y-p2.y)*(p1.y-p2.y)));
}
void init(int n,int m)
{
int i,j;
tops=0;
int a,b,c;
ts=0;
for(i=0;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
ts++;
yuan(a,b,c);
}
for(i=0;i<m;i++)
for(j=0;j<3;j++)
{
scanf("%lf%lf",&point[tops].x,&point[tops].y);
point[tops].pos=0;
tops++;
}
}
void jiantu()
{
int i;
sort(point,point+tops,cmp1);
sort(point+1,point+tops,cmp2);
tu[0]=point[0];
tu[1]=point[1];
tu[2]=point[2];
num=3;
for(i=3;i<tops;i++)
{
while(!pan(i,num-1,num-2))num--;
tu[num++]=point[i];
}
}
void print()
{
double lens;
int i;
lens=0.0;
for(i=0;i<num;i++)
{
if(tu[i].pos>0&&(tu[i].pos==tu[(i+1)%num].pos))
{
lens+=1.0*tu[i].r*2*PI/500.0;
}
else
lens+=len(tu[i],tu[(i+1)%num]);
}
printf("%.5lf\n",lens);
}
int main()
{
int n,m;
// freopen("1002.in","r",stdin);
while(~scanf("%d%d",&n,&m))
{
init(n,m);
jiantu();
print();
}
return 0;
}

HDU 4667 Building Fence的更多相关文章

  1. HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)

    Building Fence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  2. HDU 4667 Building Fence(求凸包的周长)

    A - Building Fence Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u ...

  3. HDU 4667 Building Fence 计算几何 凸包+圆

    1.三角形的所有端点 2.过所有三角形的端点对所有圆做切线,得到所有切点. 3.做任意两圆的外公切线,得到所有切点. 对上述所有点求凸包,标记每个点是三角形上的点还是某个圆上的点. 求完凸包后,因为所 ...

  4. hdu 4667 Building Fence < 计算几何模板>

    //大白p263 #include <cmath> #include <cstdio> #include <cstring> #include <string ...

  5. 4667 Building Fence 解题报告

    题意:给n个圆和m个三角形,且保证互不相交,用一个篱笆把他们围起来,求最短的周长是多少. 解法1:在每个圆上均匀的取2000个点,求凸包周长就可以水过. 解法2:求出所有圆之间的外公切线的切点,以及过 ...

  6. HDU 5033 Building(单调栈)

    HDU 5033 Building(单调栈) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5033 Description Once upon a ti ...

  7. HDU—— 5159 Building Blocks

    Problem Description After enjoying the movie,LeLe went home alone. LeLe decided to build blocks. LeL ...

  8. HDU 5033 Building

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5033 解题报告:在一条x轴上有n个建筑物,每个建筑物有一个高度h,然后现在有q次查询,查询的内容是假设 ...

  9. hdu 2818 Building Block

    Building Block Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)

    题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...

  2. js解决快速回车重复订单提交(客户端方式)

    Html代码: <form action="order_add_data.php" method="post" name="order_adds ...

  3. (转)每天一个Linux命令(4): mkdir

    http://www.cnblogs.com/peida/archive/2012/10/25/2738271.html linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前 ...

  4. poj 1986 Distance Queries

    好像是模板题  当作练习题 不错:  要求任意两点之间的距离.可以假设一个根节点,然后所有点到根节点的距离,然后求出任意两点多公共祖先:  距离就变成了 dis[u]+dis[v] - 2*dis[ ...

  5. Linux/Unix shell 脚本监控磁盘可用空间

    Linux下监控磁盘的空闲空间的shell脚本,对于系统管理员或DBA来说,必不可少.下面是给出的一个监控磁盘空间空间shell脚本的样本,供大家参考. 1.监控磁盘的空闲空间shell脚本 robi ...

  6. Android 一步一步教你使用ViewDragHelper

    在自定义viewgroup的时候 要重写onInterceptTouchEvent和onTouchEvent 这2个方法 是非常麻烦的事情,好在谷歌后来 推出了ViewDragHelper这个类.可以 ...

  7. CSS打造三级下拉菜单

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  8. [Papers]NSE, $u$, Lorentz space [Bjorland-Vasseur, JMFM, 2011]

    $$\bex \int_0^T\frac{\sen{\bbu}_{L^{q,\infty}}^p}{\ve+\ln \sex{e+\sen{\bbu}_{L^\infty}}}\rd s<\in ...

  9. Android的Adapter用法

    1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(ListView,GridView)等地方都需要用到Adapter.如下图直 ...

  10. jQuery插件开发的模式和结构

    jQuery插件开发 一般来说,jQuery插件的开发分为两种:一种是挂在jQuery命名空间下的全局函数,也可称为静态方法:另一种是jQuery对象级别的方法,即挂在jQuery原型下的方法,这样通 ...