bzoj2178: 圆的面积并
Description
Input
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: 圆的面积并的更多相关文章
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- BZOJ2178: 圆的面积并(格林公式)
题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...
- BZOJ2178 圆的面积并 计算几何 辛普森积分
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...
- BZOJ2178 圆的面积并(simpson积分)
板子题.可以转一下坐标防止被卡.精度和常数实在难以平衡. #include<iostream> #include<cstdio> #include<cmath> # ...
- 【BZOJ2178】圆的面积并(辛普森积分)
[BZOJ2178]圆的面积并(辛普森积分) 题面 BZOJ 权限题 题解 把\(f(x)\)设为\(x\)和所有圆交的线段的并的和. 然后直接上自适应辛普森积分. 我精度死活一个点过不去,不要在意我 ...
- 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]
[题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...
- JAVA求圆的面积
import java.text.DecimalFormat;import java.util.Scanner; public class TheAreaOfCircle { public stati ...
- c语言求平面上2个坐标点的直线距离、求俩坐标直线距离作为半径的圆的面积、递归、菲波那次数列、explode
#include <stdio.h> #include <math.h> #include <string.h> char explode( char * str ...
- 【BZOJ】2178: 圆的面积并
http://www.lydsy.com/JudgeOnline/problem.php?id=2178 题意:给出n<=1000个圆,求这些圆的面积并 #include <cstdio& ...
随机推荐
- JS基础知识(基本类型 引用类型)
1,js中的 基本类型 引用类型 javascript中有两种变量类型:基本类型和引用类型,基本类型包括:Number.String.Undefined.Null.Boolean这五种,而引用类型 ...
- 递归神经网络之理解长短期记忆网络(LSTM NetWorks)(转载)
递归神经网络 人类并不是每时每刻都从头开始思考.正如你阅读这篇文章的时候,你是在理解前面词语的基础上来理解每个词.你不会丢弃所有已知的信息而从头开始思考.你的思想具有持续性. 传统的神经网络不能做到这 ...
- cdoj 482 优先队列+bfs
Charitable Exchange Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- keil uvision看厌了么?试试Sublime Text吧!
之前用 Sublime Text(以下简称 ST )配置了 C/C++ 开发环境,感觉相当不错,作为编辑器的 ST,编辑代码的功能当然是相当棒的,美中不足的是目前只能编译单个文件,但是用来做些小练习也 ...
- js 如何判断页面里的某个值改变
程序未改变变量的值前新增全局变量:var oldDivValue = document.getElementById("divid").innerHTML; 程序在改变变量值后执行 ...
- leetcode 121. Best Time to Buy and Sell Stock ----- java
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- JavaWeb学习记录(二)——防盗链技术
public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpSer ...
- Hibernate——property的access属性
public class Customer implements Serializable { private static final long serialVersionUID = 1L; ...
- 20145220《Java程序设计》实验一实验报告
*实验一 Java开发环境的熟悉 实验内容及步骤 使用JDK编译.运行简单的Java程序 命令行下程序开发: 在命令行下建立实验目录,进入该目录后创建exp1目录 敲入以下代码: package ex ...
- min-height for IE6
1. className{ min-height:500px; height:auto !important; height:500px; } 2. 在做页面布局时遇到了i ...