题意:

给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. 【同行说技术】iOS程序员从小白到大神必读资料汇总

    在文章<iOS程序员从小白到大神必读资料汇总(一)>里面介绍了很多iOS入门学习的资料,今天小编就发几篇技术进阶的文章,快来看看吧! 一.iOS后台模式开发指南 这个教程会教你在什么时候怎 ...

  2. The Guide To Understanding mysqlreport

    The Guide To Understanding mysqlreport This guide to understanding mysqlreport explains everything t ...

  3. application tips

    trace(ApplicationDomain.currentDomain == ApplicationDomain.currentDomain); trace(stage.loaderInfo.ap ...

  4. 深入学习Heritrix---解析处理器(Processor)(转)

    深入学习Heritrix---解析处理器(Processor) 本节解析与处理器有关的内容. 与处理器有关的主要在以下几个类:Processor(处理器类),ProcessorChain(处理器类), ...

  5. oracle----sqlldr用法

    SQL*LOADER是ORACLE的数据加载工具,通常用来将操作系统文件迁移到ORACLE数据库中.SQL*LOADER是大型数据仓库选择使用的加载方法,因为它提供了最快速的途径(DIRECT,PAR ...

  6. 为Linux版本Oracle 11gR2配置HugePage

    HugePage是Oracle在Linux版本下一种性能优化手段.对于共享内存区域(SGA)的数据库系统,Oracle通常都推荐在操作系统层面配置上HugePage,为Oracle实例准备更大的可用共 ...

  7. getHibernateTemplate() 一直报NullPointerException 错误

    原来是调用方法有误正确调用方法: ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContex ...

  8. 12、NFC技术:读写NFC标签中的Uri数据

    功能实现,如下代码所示: 读写NFC标签的Uri 主Activity import cn.read.write.uri.library.UriRecord; import android.app.Ac ...

  9. 基于opencv的人脸检测的web应用

    参考资料 https://github.com/bsdnoobz/web-based-face-detect http://opencv-code.com/projects/web-based-int ...

  10. 【LeetCode】217 & 219 - Contains Duplicate & Contains Duplicate II

     217 - Contains Duplicate Given an array of integers, find if the array contains any duplicates. You ...