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. Xen虚拟机磁盘镜像模板制作(一)—Windows Server 2008(2012)

    这段时间一直在研究如何制作一个适合Xen虚拟化的Windows Server 2008(2012)磁盘镜像,中间虽然遇到了一些阻挠,不过最终还是顺利解决,成功制作出了Xen Windows Serve ...

  2. 94. Binary Tree Inorder Traversal

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  3. python--切片--6

    原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 一.对list进行切片 取一个list的部分元素是非常常见的操作.比如,一个list如下: &g ...

  4. spark-DataFrame之RDD和DataFrame之间的转换

    package cn.spark.study.core.mycode_dataFrame; import java.io.Serializable;import java.util.List; imp ...

  5. scala言语基础学习十二

  6. timus 1136 Parliament(二叉树)

    Parliament Time limit: 1.0 secondMemory limit: 64 MB A new parliament is elected in the state of MMM ...

  7. wordpress(一)wordpress环境的搭建

    搭建wordpress环境因为自动安装的脚本不提供创建数据库的功能,所以先要创建数据库. 1.使用如下命令创建数据库(都是在已经登陆的mysql界面中的命令) ①CREATE DATABASE 数据库 ...

  8. caffe: compile error : undefined reference to `cv::imread(cv::String const&, int)' et al.

    when I compile caffe file : .build_debug/lib/libcaffe.so: undefined reference to `cv::imread(cv::Str ...

  9. ADS1110/ADS1271

    ADS1110 1.初始化 软件:设置p任意2个为GPIO口 硬件:设置p0.2,p0.3为SDA,SCL 输入.输出 ADS1110的I2C地址(1001aaa)例如ADS1110A0的地址是100 ...

  10. Softmax回归(使用tensorflow)

    # coding:utf8 import numpy as np import cPickle import os import tensorflow as tf class SoftMax: def ...