题意:

给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. 51nod 博弈论水题

    51nod1069 Nim游戏 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误 ...

  2. php多种实例理解无限极分类

  3. 【转】Xcode添加静态库以及编译选项配置常见问题

    原文网址:http://www.cnblogs.com/Quains/p/3276425.html 一,Xcode编译出现Link错误,出现"duplicate symbols for ar ...

  4. Symfony2学习笔记之数据库操作

    数据库和Doctrine让我们来面对这个对于任何应用程序来说最为普遍最具挑战性的任务,从数据库中读取和持久化数据信息.幸运的是,Symfony和Doctrine进行了集成,Doctrine类库全部目标 ...

  5. hdu 2177(威佐夫博奕)

    题意:容易理解,在威佐夫博奕的基础上新增加了一条要求:就是如果在赢得条件下,输出第一步怎么走. 分析:使用暴力判断,详细见代码. 代码: #include<stdio.h> #includ ...

  6. hibernate建表 一对多 多的一方控制一的一方

    一对多 单向<one-to-many>通过calss操作student 外键在student表中,所以外键由student维护<many-to-one>通过student操作c ...

  7. 题目1003:A+B ---c_str(),atoi()函数的使用;remove , erase函数的使用

    #include<stdio.h> #include<stdlib.h> int sw(char *a){ ,c=; while(a[i]){ ') c=c*+a[i]-'; ...

  8. 企业网站DDOS防护解决方案

    随着网络的普及,越来越多的企业开始了上网之路,由于网络安全知识的欠缺,很多企业以为做一个网站就 等于 网络化了,于是狠花血本请专业网络公司制作出各种漂亮的网页.但做完才发现,网络上的各种漏洞的DDOS ...

  9. 运行Python2.x程序报编码错误的解决办法-UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 7: ordina not in range(128)

    Python编码问题的终极解决方案:在python的Lib\site-packages文件夹下新建一个sitecustomize.py文件,输入: import sys sys.setdefaulte ...

  10. [转]Linux的chattr与lsattr命令详解

    转自:http://www.cnblogs.com/yangxia-test/archive/2013/05/24/3096410.html 这两个命令是用来查看和改变文件.目录属性的,与chmod这 ...