Description

给出N个圆,求其面积并

Input

先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数

Output

面积并,保留三位小数
简单说就是去除被包含的圆,求出每个圆的圆周未被其他圆覆盖的圆弧,求对应弓形的面积以及弓形的弦与原点构成的三角形的有向面积。
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long double ld;
int n;
const ld pi=acos(-.l),_2pi=pi*;
struct itv{ld l,r;}is[];
bool operator<(itv x,itv y){return x.l<y.l;}
int ip;
ld ans=;
ld maxs(ld&a,ld b){if(a<b)a=b;}
struct cir{
int x,y,r;
void init(){scanf("%d%d%d",&x,&y,&r);}
bool in(cir w){
int a=x-w.x,b=y-w.y;
return sqrt(a*a+b*b)+r-1e-7l<w.r;
}
bool cross(cir w){
int a=x-w.x,b=y-w.y;
return sqrt(a*a+b*b)<r+w.r;
}
ld fix(ld x){
while(x<)x+=_2pi;
while(x>_2pi)x-=_2pi;
return x;
}
void cal(cir w){
ld xd=w.x-x,yd=w.y-y,d=sqrt(xd*xd+yd*yd);
ld a=atan2(yd,xd);
ld b=acos((r*r+d*d-w.r*w.r)/(*r*d));
ld l=fix(a-b),r=fix(a+b);
if(l<r)is[ip++]=(itv){l,r};
else is[ip++]=(itv){,r},is[ip++]=(itv){l,_2pi};
}
inline void g1(ld a){
ans+=(a-sin(a))*r*r;
}
inline void g2(ld L,ld R){
ans+=((x+cos(L)*r)*(y+sin(R)*r)-(x+cos(R)*r)*(y+sin(L)*r));
}
void get(){
if(!ip){
ans+=pi*r*r*;
return;
}
std::sort(is,is+ip);
ld L,R=-,R1;
for(int i=,j=;i<ip;i=j){
R1=R;L=is[i].l;R=is[i].r;
while(j<ip&&is[j].l<=R)maxs(R,is[j++].r);
if(R1!=-)g1(L-R1),g2(R1,L);
}
g1(is[].l+_2pi-R),g2(R,is[].l+_2pi);
}
}cs[];
int main(){
scanf("%d",&n);
for(int i=;i<n;++i)cs[i].init();
for(int i=;i<n;++i){
for(int j=;j<n;++j)if(i!=j&&cs[i].in(cs[j])){
cs[i--]=cs[--n];
break;
}
}
for(int i=;i<n;++i){
ip=;
for(int j=;j<n;++j)if(i!=j&&cs[i].cross(cs[j])){
cs[i].cal(cs[j]);
}
cs[i].get();
}
printf("%.3Lf",ans/.);
return ;
}

bzoj2178: 圆的面积并的更多相关文章

  1. [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并

    [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...

  2. BZOJ2178: 圆的面积并(格林公式)

    题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...

  3. BZOJ2178 圆的面积并 计算几何 辛普森积分

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...

  4. BZOJ2178 圆的面积并(simpson积分)

    板子题.可以转一下坐标防止被卡.精度和常数实在难以平衡. #include<iostream> #include<cstdio> #include<cmath> # ...

  5. 【BZOJ2178】圆的面积并(辛普森积分)

    [BZOJ2178]圆的面积并(辛普森积分) 题面 BZOJ 权限题 题解 把\(f(x)\)设为\(x\)和所有圆交的线段的并的和. 然后直接上自适应辛普森积分. 我精度死活一个点过不去,不要在意我 ...

  6. 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]

    [题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...

  7. JAVA求圆的面积

    import java.text.DecimalFormat;import java.util.Scanner; public class TheAreaOfCircle { public stati ...

  8. c语言求平面上2个坐标点的直线距离、求俩坐标直线距离作为半径的圆的面积、递归、菲波那次数列、explode

    #include <stdio.h> #include <math.h> #include <string.h> char explode( char * str ...

  9. 【BZOJ】2178: 圆的面积并

    http://www.lydsy.com/JudgeOnline/problem.php?id=2178 题意:给出n<=1000个圆,求这些圆的面积并 #include <cstdio& ...

随机推荐

  1. vcf_filter.py

    pyvcf 中带的一个工具 比其他工具用着好些 其他filter我很信不过~~  自己写的功能又很有限 所以转投vcf_filter.py啦 Filtering a VCF file based on ...

  2. (实用篇)微信网页授权(OAuth2.0) PHP 源码简单实现

    提要: 1. 建议对OAuth2.0协议做一个学习. 2. 微信官方文档和微信官网工具要得到充分利用. 比较简单,直接帖源代码了.其中"xxxxxxxxxx"部分,是需要依据自己环 ...

  3. PotPlayer播放器——最强大的播放器 - imsoft.cnblogs

    PotPlayer下载:链接 http://pan.baidu.com/s/17vgMM 密码: 8buc PotPlayer关联图标修改方法:打开安装目录替换目录下的PotIcons.dll文件即可 ...

  4. left join测试验证之一

    $ sqlite3 a.dbSQLite version 3.8.1 2013-10-17 12:57:35Enter ".help" for instructionsEnter ...

  5. Android ADT初始化失败

    在android的官网上买下载android的adt完了,进行解压之后,开始点击 eclipse.exe,果然给了我一个惊喜,那就是 [ Failed to create the Java Virtu ...

  6. linux文件系统---10

    进入 Linux 根目录(即“/”, Linux 文件系统的入口, 也是处于最高一级的目录),运行“ls –l”命令,可以看到 Linux 系统包含以下目录. 1./bin 包含基本命令,如 ls.c ...

  7. leetcode 106 Construct Binary Tree from Inorder and Postorder Traversal----- java

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  8. leetcode 102 Binary Tree Level Order Traversal ----- java

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  9. URAL 2034 Caravans(变态最短路)

    Caravans Time limit: 1.0 secondMemory limit: 64 MB Student Ilya often skips his classes at the unive ...

  10. 三步将Node应用部署到Heroku上 --转载

    Heroku是一个提供快速部署服务的云平台.支持Node,Ruby,Java,PHP,Python,Go多种语言,今天体验了下,简直不要太爽.下面简单的介绍一下. 首先还是要注册一个账号:https: ...