Long long ago, there is a famous farmer named John. He owns a big farm and many cows. There are two kinds of cows on his farm, one is Friesian, and another one is Ayrshire. Each cow has its own territory. In detail, the territory of Friesian is a circle, and of Ayrshire is a triangle. It is obvious that each cow doesn't want their territory violated by others, so the territories won't intersect.

Since the winter is falling, FJ has to build a fence to protect all his cows from hungry wolves, making the territory of cows in the fence. Due to the financial crisis, FJ is currently lack of money, he wants the total length of the fence minimized. So he comes to you, the greatest programmer ever for help. Please note that the part of fence don't have to be a straight line, it can be a curve if necessary.

Input

The input contains several test cases, terminated by EOF. The number of test cases does not exceed 20.

Each test case begins with two integers N and M(0 ≤ N, M ≤ 50, N + M > 0)which denotes the number of the Friesian and Ayrshire respectively. Then follows N + M lines, each line representing the territory of the cow. Each of the first N lines contains three integers X i, Y i, R i(1 ≤ R i ≤ 500),denotes the coordinates of the circle's centre and radius. Then each of the remaining M lines contains six integers X1 i, Y1 i, X2 i, Y2 i, X3 i, Y3 i, denotes the coordinates of the triangle vertices. The absolute value of the coordinates won't exceed 10000.

Output

For each test case, print a single line containing the minimal fence length. Your output should have an absolute error of at most 1e-3.

Sample Input

1 1

4 4 1

0 0 0 2 2 0

Sample Output

15.66692

Hint

Please see the sample picture for more details, the fence is highlighted with red.

发现类似凸包,但是圆没法解决,做法是把圆拆开来就好了,拆成一千个点,然后套模板,求周长的话,可以直接求没两点距离,想要精确度高一点,可以在圆的点做个标记,是哪个圆,半径是多少,然后求的时候如果是同一个圆就算弧长

直接求距离的

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
const db eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int INF=0xfffffff;
struct Point
{
double x,y;
}p[150+50*2000],s[150+50*2000];
int top;
double direction(Point p1,Point p2,Point p3) {
double ans=(p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y);
return ans; }//点2和3,按哪个和点一的角度更小排,相同的话按哪个更近排
double dis(Point p1,Point p2) { return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); }
bool cmp(Point p1,Point p2)//极角排序
{
double temp=direction(p[0],p1,p2);
if(fabs(temp)<eps) temp=0;
if(temp<0)return true ;
if(temp==0&&dis(p[0],p1)<dis(p[0],p2))return true;
return false;
}
void Graham(int n)
{
int pos;
double minx,miny;
minx=miny=INF;
for(int i=0;i<n;i++)//找最下面的基点
if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
swap(p[0],p[pos]);
sort(p+1,p+n,cmp);
p[n]=p[0];
//sort(p+2,p+n,cmp1);
s[0]=p[0];s[1]=p[1];s[2]=p[2];
top=2;
for(int i=3;i<=n;i++)
{
while(direction(s[top-1],s[top],p[i])>=0&&top>=2)
top--;
s[++top]=p[i] ;
}
}
int main()
{
int n,m;
while(~sf("%d%d",&m,&n))
{
double x,y,r;
int ans=0;
while(m--)
{
sf("%lf%lf%lf",&x,&y,&r);
rep(i,0,2000)
{
p[ans].x=x+r*cos(2.0*pi*i/2000);
p[ans++].y=y+r*sin(2.0*pi*i/2000);
}
}
while(n--)
{
sf("%lf%lf%lf%lf%lf%lf",&p[ans].x,&p[ans].y,&p[ans+1].x,&p[ans+1].y,&p[ans+2].x,&p[ans+2].y);
ans+=3;
}
Graham(ans);
double sum=0;
s[top]=s[0];
rep(i,0,top)
{
sum+=dis(s[i],s[i+1]);
}
pf("%.5lf\n",sum);
} return 0;
}

求弧长的

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
const db eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int INF=0xfffffff;
struct Point
{
double x,y,id,r;
}p[150+50*1002],s[150+50*1002];
int top;
double direction(Point p1,Point p2,Point p3) { double ans=(p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y);return ans; }//点2和3,按哪个和点一的角度更小排,相同的话按哪个更近排
double dis(Point p1,Point p2) { return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); }
bool cmp(Point p1,Point p2)//极角排序
{
double temp=direction(p[0],p1,p2);
if(fabs(temp)<eps) temp=0;
if(temp<0)return true ;
if(temp==0&&dis(p[0],p1)<dis(p[0],p2))return true;
return false;
}
void Graham(int n)
{
int pos;
double minx,miny;
minx=miny=INF;
for(int i=0;i<n;i++)//找最下面的基点
if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
swap(p[0],p[pos]);
sort(p+1,p+n,cmp);
p[n]=p[0];
s[0]=p[0];s[1]=p[1];s[2]=p[2];
top=2;
for(int i=3;i<=n;i++)
{
while(direction(s[top-1],s[top],p[i])>=0&&top>=2)
top--;
s[++top]=p[i] ;
}
}
int main()
{
int n,m; while(~sf("%d%d",&m,&n))
{ double x,y,r;
int ans=0;
int ID=1;
while(m--)
{
sf("%lf%lf%lf",&x,&y,&r);
rep(i,0,1000)
{
p[ans].id=ID;
p[ans].r=r;
p[ans].x=x+r*cos(2.0*pi*i/1000);
p[ans++].y=y+r*sin(2.0*pi*i/1000);
}
ID++;
}
while(n--)
{
sf("%lf%lf%lf%lf%lf%lf",&p[ans].x,&p[ans].y,&p[ans+1].x,&p[ans+1].y,&p[ans+2].x,&p[ans+2].y);
p[ans].id=0;
p[ans+1].id=0;
p[ans+2].id=0;
ans+=3;
}
Graham(ans);
double sum=0;
rep(i,0,top)
if(s[i].id>0&&(s[i].id==s[(i+1)%top].id))
sum+=1.0*s[i].r*2*pi/1000.0;
else
sum+=dis(s[i],s[(i+1)%top]);
pf("%.5lf\n",sum);
} return 0;
}

C - 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

    题意: 给n个圆和m个三角形,且保证互不相交,用一个篱笆把他们围起来,求最短的周长是多少. 做法:--水过... 把一个圆均匀的切割成500个点,然后求凸包. 注意:求完凸包,在求周长的时候记得要把圆 ...

  4. 4667 Building Fence 解题报告

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

  5. [hdu4667]Building Fence 计算几何 瞎瘠薄搞

    大致题意: 给出n个圆和m个三角形,求最小的的,能将所有图形覆盖的图形的周长. 正解为求所有三角形顶点与圆的切点以及圆和圆的切点构造凸包,再求路径. 因为要求结果误差<=1e-3 所以 我们可以 ...

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

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

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

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

  8. 【 2013 Multi-University Training Contest 7 】

    HDU 4666 Hyperspace 曼哈顿距离:|x1-x2|+|y1-y2|. 最远曼哈顿距离,枚举x1与x2的关系以及y1与y2的关系,取最大值就是答案. #include<cstdio ...

  9. poj 1037 A decorative fence

    题目链接:http://poj.org/problem?id=1037 Description Richard just finished building his new house. Now th ...

随机推荐

  1. Android典型界面设计(8) ——ViewPager+PagerSlidingTabStrip实现双导航

    一.问题描述 PagerSlidingTabStrip是android开源项目,指示器控件.官网地址:https://github.com/astuetz/PagerSlidingTabStrip 该 ...

  2. Java 下一代: 函数式编码风格——Groovy、Scala 和 Clojure 共享的函数结构及其优势

    原文地址 本文内容 命令式处理 函数式处理 函数式编程的优势 所有 Java 下一代语言都包括函数式编程结构,让您可以从一个更高的抽象层面来思考问题.然而,语言间术语的不同使得难以看到类似的结构.本期 ...

  3. 魅族便签,是否能成为国内便签应用的No.1?

    继前不久锤子科技推出便签 Android 新版后,近期魅族在PRO 6公布会上也公布了最新的魅族便签应用.这一次魅族把便签应用拓展到了整个Android体系,也就是说.其它不论什么的Android手机 ...

  4. 〖Linux〗Kubuntu 14.04的Eclipse 崩溃解决方法总结

    1. 普通崩溃问题: eclipse/configuration/config.ini在后边添加 org.eclipse.swt.browser.DefaultType=mozilla 2. Kubu ...

  5. mysql存储引擎的一点学习心得总结

    首先我们应该了解mysql中的一个重要特性--插件式存储引擎,从名字就能够看出在mysql中,用户能够依据自己的需求随意的选择存储引擎.实际上也是这样.即使在同一个数据库中.不同的表也能够使用不同的存 ...

  6. 最经典的常用拍照姿势大全,顶级POSE

    伸出手遮阳光.   捂住一只眼睛.   手放在最旁.这是一个极具诱惑的姿势 站立,背对镜头,扭过来,仰角拍, 俩手按在头两边,歪头,或者直头,表情一般都困惑,迷茫,咬下嘴唇效果更佳.         ...

  7. [转]抛弃jQuery,使用原生JavaScript

    原文链接 Document Ready 事件 在jQuery中,document.ready可以让代码在整个文档加载完毕之后执行: $(document).ready(function() { // ...

  8. Database数据库切片模式

    数据库切片模式关注的实现水平伸缩.切分是从单个数据库到平分数据访问两个或更多数据库切片.每个切片有和原始数据库相同的Schema.大多数据分布在每个切片每一行.从切片合并起来的数据和原始数据库一样.切 ...

  9. 大型互联网架构概述 关于架构的架构目标 典型实现 DNS CDN LB WEB APP SOA MQ CACHE STORAGE

    大型互联网架构概述 目录 架构目标 典型实现 DNS CDN LB WEB APP SOA MQ CACHE STORAGE 本文旨在简单介绍大型互联网的架构和核心组件实现原理. 理论上讲,从安装配置 ...

  10. iOS开发之Xcode9报错 Compiling IB documents for earlier than iOS7 is no longer supported.

    升级到Xcode9时,最低的编译版本为iOS8,但是在使用一些SDK的时候就会报出Compiling IB documents for earlier than iOS7 is no longer s ...