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. Think Python - Chapter 17 - Classes and methods

    17.1 Object-oriented featuresPython is an object-oriented programming language, which means that it ...

  2. 八 JDBC

    一 JDBC 简介 1. 作用:规避数据库的不同,为程序开发人员访问数据库提供统一的编程接口. 2. 具体作用:和数据库建立连接,发送 sql 语句,处理数据库返回的结果集. 3. 框架模式: 4. ...

  3. 使用ASP.NET web API创建REST服务(三)

    本文档来源于:http://www.cnblogs.com/madyina/p/3390773.html Creating a REST service using ASP.NET Web API A ...

  4. JSON日期格式处理

    protected static SerializeConfig mapping = new SerializeConfig(); private static String dateFormat; ...

  5. QAQ

    贴吧怎么了最近多了一些脑残帖子 回答完问题你追我 ? 你追你mb你车费都凑不够. 答着答着你也许就哭了 我哭你mb 老子脑袋又没病 . 英国最最虐心的调查 ,我虐你mb还英国 你出过省吗? 晚上回家 ...

  6. python爬虫抓网页的总结

    python爬虫抓网页的总结 更多 python 爬虫   学用python也有3个多月了,用得最多的还是各类爬虫脚本:写过抓代理本机验证的脚本,写过在discuz论坛中自动登录自动发贴的脚本,写过自 ...

  7. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  8. Vue.js相关知识4-路由

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. mysql时间类型在iBATIS框架下的问题(原创哦)

    写代码时遇到一个没有搜到的错误,简单记录一下这个dubbo框架中出现的问题. 启动dubbo一个服务端的bat时报错如下

  10. C++@语句块

    #include <iostream> using namespace std; int main() { { int x=1; cout << x << endl ...