题目大意:

给定m r 初始圆盘以原点为圆心半径为r

给定m个圆的圆心(x,y) 半径r 保证m个圆互不相交且不会覆盖圆盘

用这m个圆来切割初始的圆盘求最后圆盘外围的长度

求圆与圆盘的交点

减去圆盘上两点间的周长 加上圆上两点间的周长 判断一下方向

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define PI acos(-1)
#define pb(a) push_back(a)
#define mem(i,j) memset(i,j,sizeof(i))
const int N=1e5+;
const int MOD=1e9+;
const double eps=1e-; double add(double a,double b) {
if(abs(a+b)<eps*(abs(a)+abs(b))) return ;
return a+b;
}
int dcmp(double x) {
if(abs(x)<eps) return ;
else return x< ? -:;
}
struct P {
double x,y;
P(){} P(double _x,double _y):x(_x),y(_y){}
P operator - (P p) { return P(add(x,-p.x),add(y,-p.y)); }
P operator + (P p) { return P(add(x,p.x),add(y,p.y)); }
P operator * (double d) { return P(x*d,y*d); }
P operator / (double d) { return P(x/d,y/d); }
double dot (P p) { return add(x*p.x,y*p.y); }
double det (P p) { return add(x*p.y,-y*p.x); }
bool operator == (const P& p)const {
return abs(x-p.x)<eps && abs(y-p.y)<eps; }
bool operator < (const P& p)const {
return x<p.x || (x==p.x && y<p.y); }
};
struct L {
P p, v; double ang;
L(){} L(P _p,P _v):p(_p),v(_v){ ang=atan2(v.y,v.x); }
P acP(double t) { return p+v*t; }
};
struct C {
P p; double r;
C(){} C(P _p,double _r):p(_p),r(_r){}
P acP(double a) { return P(p.x+cos(a)*r,p.y+sin(a)*r); }
double AL(double ang) { return ang*r; }
}c;
// 求向量a的长度
double lenP(P a) { return sqrt(a.dot(a)); }
// 求向量v极角
double angle(P v) { return atan2(v.y,v.x); }
// 求两向量夹角
double Angle(P u,P v) { return acos(u.dot(v)/lenP(u)/lenP(v));}
/* 判断两圆相交
求圆c1与c2的交点 并用s保存交点
w记录是外切1还是内切-1
*/
int insCC(C c1,C c2,vector<P>& s,int* w) {
double d=lenP(c1.p-c2.p);
if(abs(d)<eps) {
if(abs(c1.r-c2.r)<eps) return -; // 重合
return ; // 内含
}
if((c1.r+c2.r-d)<-eps) return ; // 外离
if(d-abs(c1.r-c2.r)<-eps) return ; // 内离 (*w)=dcmp(d-c1.r);
double ang=angle(c2.p-c1.p); // 向量c1c2求极角
double da=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(*c1.r*d));
// c1与交点的向量 与 c1c2 的夹角
P p1=c1.acP(ang-da), p2=c1.acP(ang+da); // 求得两交点 s.pb(p1);
if(p1==p2) return ; // 同一个点
s.pb(p2); return ;
} int main()
{
int t; scanf("%d",&t);
while(t--) {
int m; double r;
scanf("%d%lf",&m,&r);
c.p.x=c.p.y=, c.r=r;
double ans=2.0*PI*c.r;
while(m--) {
//printf("%lf\n",ans);
C t; scanf("%lf%lf%lf",&t.p.x,&t.p.y,&t.r);
vector <P> p; p.clear();
int w, s=insCC(c,t,p,&w);
if(s==) {
if(w==-) ans+=2.0*PI*t.r;
} else if(s==) {
P u=p[], v=p[];
double ang=Angle(u,v);
if(dcmp(u.det(v))<) ang=2.0*PI-ang;
ans-=c.AL(ang); /// 减去圆盘被切的部分周长
u=p[]-t.p, v=p[]-t.p;
ang=Angle(u,v);
if(dcmp(u.det(v))>) ang=2.0*PI-ang;
ans+=t.AL(ang); /// 加上切割产生的新边缘
}
}
printf("%.10f\n",ans);
} return ;
}

也可以用余弦定理 https://www.cnblogs.com/Dillonh/p/9433714.html

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define PI acos(-1)
#define pb(a) push_back(a)
#define mem(i,j) memset(i,j,sizeof(i))
const int N=1e5+;
const int MOD=1e9+;
const double eps=1e-; double add(double a,double b) {
if(abs(a+b)<eps*(abs(a)+abs(b))) return ;
return a+b;
}
int dcmp(double x) {
if(abs(x)<eps) return ;
else return x< ? -:;
}
struct P {
double x,y;
P(){} P(double _x,double _y):x(_x),y(_y){}
P operator - (P p) { return P(add(x,-p.x),add(y,-p.y)); }
P operator + (P p) { return P(add(x,p.x),add(y,p.y)); }
P operator * (double d) { return P(x*d,y*d); }
P operator / (double d) { return P(x/d,y/d); }
double dot (P p) { return add(x*p.x,y*p.y); }
double det (P p) { return add(x*p.y,-y*p.x); }
bool operator == (const P& p)const {
return abs(x-p.x)<eps && abs(y-p.y)<eps; }
bool operator < (const P& p)const {
return x<p.x || (x==p.x && y<p.y); }
};
struct C {
P p; double r;
C(){} C(P _p,double _r):p(_p),r(_r){}
P acP(double a) { return P(p.x+cos(a)*r,p.y+sin(a)*r); }
double AL(double ang) { return ang*r; }
}c;
// 求向量a的长度
double lenP(P a) { return sqrt(a.dot(a)); }
double change(C t) {
double D=lenP(t.p);
if(dcmp(c.r-t.r-D)>) return ; // 内离
if(dcmp(c.r-t.r-D)==) return 2.0*PI*t.r; // 内切
if(dcmp(c.r+t.r-D)<=) return ; // 外离 外切
double angc=acos((c.r*c.r+D*D-t.r*t.r)/(2.0*c.r*D));
double angt=acos((t.r*t.r+D*D-c.r*c.r)/(2.0*t.r*D));
return t.AL(angt*2.0)-c.AL(angc*2.0);
} int main()
{
int t; scanf("%d",&t);
while(t--) {
int m; double r;
scanf("%d%lf",&m,&r);
c.p.x=c.p.y=, c.r=r;
double ans=2.0*PI*c.r;
while(m--) {
C t; scanf("%lf%lf%lf",&t.p.x,&t.p.y,&t.r);
ans+=change(t);
}
printf("%.10f\n",ans);
} return ;
}

hdu6354 /// 圆的相交的更多相关文章

  1. hdu6354 Everything Has Changed (圆的相交弧长)

    题目传送门 题意: 用一堆圆来切割一个圆心为原点,半径为R的圆A,问切割完毕后圆A外围剩余部分的周长(图中的红线部分). 思路: 首先判定圆与圆A的关系,这题我们只需要与A内切.相交的圆. 然后就是求 ...

  2. codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述

    之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...

  3. Everything Has Changed(HDU6354+圆交+求周长)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6354 题目: 题意:用一堆圆来切割一个圆心为原点,半径为R的圆A,问切割完毕后圆A外围剩余部分的周长( ...

  4. hdu1174(3维射线与圆是否相交)

    简单的题意,要注意z2 = h2*0.9-r2 #include <iostream> #include <cmath> #include <vector> #in ...

  5. 多边形和圆的相交面积(模板)hdu2892、hdu4404

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

  6. HDU 3467 (求五个圆相交面积) Song of the Siren

    还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢 题意: 在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位 ...

  7. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  8. CodeForces 8D Two Friends 判断三个圆相交

    题意: 有两个人\(Alan\)和\(Bob\),他们现在都在\(A\)点,现在\(Bob\)想去\(B\)点,\(Alan\)想先到\(C\)点再去\(B\)点. \(Alan\)所走的总路程不能超 ...

  9. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

随机推荐

  1. Vue.js 入门:从零开始做一个极简 To-Do 应用

    Vue.js 入门:从零开始做一个极简 To-Do 应用 写作时间:2019-12-10版本信息:Vue.js 2.6.10官网文档:https://cn.vuejs.org/ 前言  学习 Vue ...

  2. CentOS6.5下面OpenSSH低版本升级至7.3

    升级前版本: openssl-1.0.1e-48.el6_8.1.x86_64 openssh-5.3p1-118.1.el6_8.x86_64 升级后版本: OpenSSL 1.0.2j OpenS ...

  3. CSIC_716_20191225【HTML基础入门】

    HTTP协议 超文本传输协议HyperText Transfer Protocol 四大特性: 1.一次请求一次响应 2.基于TCP/IP协议,作用于应用层 3.无状态 4.无连接 数据格式: 1.请 ...

  4. 【leetcode】955. Delete Columns to Make Sorted II

    题目如下: We are given an array A of N lowercase letter strings, all of the same length. Now, we may cho ...

  5. 【JZOJ6435】【luoguP5666】【CSP-S2019】树的重心

    description analysis 需要知道一棵树的重心一定在从根出发的重链上,可以考虑先进行树链剖分弄出重儿子和次重儿子,再倍增维护重儿子 由于重链上有一个或两个重心,接下来求的重心都是深度较 ...

  6. 如何重置Magento管理用户、角色和资源的权限

    场景1:所有的资源权限被设置为管理角色 步骤1:获取当前的管理角色详细信息 SELECT * FROM admin_role WHERE role_name = 'Administrators' /* ...

  7. Magento笔记/记录(1)

    1.Magento eav_attribute表中source如何指定自定义数据来源  如果你引用的类名为yebihai_usermanage_model_entity_school你必须完整的给出地 ...

  8. git——commit成功后,GitHub方格不变绿

    一通百度该设置的都设置了,还是不好使 发现有提示一栏 pull request的东西  在网上查貌似是因为两个分支内容不同 提示是否合并,还查到了不变绿可能的原因. Contributions未被Gi ...

  9. PHP基础知识小结

    1.PHP中类型转换 自动转换 其它类型转换数值型 true->1 false->0 null->0 'true'->0 '-3abc'->-3 '3.123abc'-& ...

  10. CSP-S考前各种idea题解乱堆

    快要考试了我还是这么菜. 已经没有心思维护我的博客了.开一篇博文吧.可能会记得很乱. 这也许是我OI生涯的最后一篇博文了?? 肯定很长很长. 不可能的.谁知道什么时候我心态恢复就把上面两句话删掉开始在 ...