题目大意:

给定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. PHP中使用raw格式发送POST请求

    如果请求的参数格式是原生(raw)的内容,应该如何为程序构造一个POST请求函数呢? function http_post($url, $data_string) { $ch = curl_init( ...

  2. overflow:hidden失效

    overflow:hidden失效 为了页面的健壮性,我们常常需要使用overflow:hidden.有时候是为了防止布局被撑开,有时候是为了配合其它规则实现文字截断,还有时候纯粹是为了创建块级上下文 ...

  3. Oracle启动或关闭归档模式

    在Oracle安装后,默认归档模式开启,大量的日志会瞬间填满磁盘,所以在开发环境,经常需要关闭归档模式. 1.管理员身份连接数据库 $sqlplus user/passwd@dbname as sys ...

  4. pytest-Allure安装

    mac安装allure brew install allure---安装 brew info allure---查看信息 mac端需要配置环境变量 win安装: windows/mac通用安装 • h ...

  5. 提交disable的Select值到后台

    需求:界面上把select控件disable,然后将默认值传到后台 问题1:select disable: js中可以这样写: document.getElementById("provin ...

  6. Spring Cloud服务保护

    微服务虽然解决了传统单体式应用各个模块之间强耦合的缺点,但同时也引出了新问题,由于微服务各个服务之间是独立部署的,并且一般情况下一个服务往往会依赖多个其他服务,并且服务之间的调用更多的是依赖不稳定的网 ...

  7. Java中this的基础用法

    update on 2019-07-07 在Java核心技术一书中看到调用方法时this作为隐式参数传入的. 突然间许多问题都懂了 比如:方法的多态 父类变量指向子类对象的引用 对象变量指向的实际类型 ...

  8. JMeter 并发压力测试

    一,下载JMeter http://jmeter.apache.org/download_jmeter.cgi 二,创建默认配置 可以不用配置相同参数. 测试计划:右键添加线程组 线程组:右键添加  ...

  9. 笔记67 Spring Boot快速入门(七)

    SpringBoot+RESTful+JSON 一.RESTful架构 REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. ...

  10. 了解跨站请求伪造CSRF

    参考以下两篇文章: https://www.cnblogs.com/Erik_Xu/p/5481441.html https://www.cnblogs.com/4littleProgrammer/p ...