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& ...
随机推荐
- [virsh] error: unknown OS type hvm解决办法
今天在linux服务器上编译安装升级了下qemu,升级命令如下: root@ubuntu:/opt/qemu-# ./configure --prefix=/usr/local/ --target-l ...
- Context启动startActivity注意
intent.setFlags()方法中参数的用例: 很多人使用startActivity时候,会碰到如下的异常:Caused by: android.util.AndroidRuntimeExcep ...
- Codeforces Round #303 (Div. 2) C dp 贪心
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- ZOJ 1089 Lotto
原题链接 题目大意:有一种抽奖游戏乐透(Lotto),规则是从1到49这49个自然数中随机抽取6个数.现在有一种简化版的游戏,先在49个数里面选出k(6<k<13)个数,然后再从这k个数里 ...
- 使用ASP.NET web API创建REST服务(三)
本文档来源于:http://www.cnblogs.com/madyina/p/3390773.html Creating a REST service using ASP.NET Web API A ...
- tiny4412SD启动盘的制作--1
一.使用SD-flasher工具烧写superboot到SD卡. 1.SD-Flasher.exe 会对 SD 卡进行分区,第一个分区为 130M 用于存放 Superboot4412, 剩下的空间格 ...
- HDU-1011 Starship Troopers (树形DP+分组背包)
题目大意:给一棵有根带点权树,并且给出容量.求在不超过容量下的最大权值.前提是选完父节点才能选子节点. 题目分析:树上的分组背包. ps:特判m为0时的情况. 代码如下: # include<i ...
- Linux comands
https://www.mankier.com/8/vmstat http://docs.oracle.com/cd/E23824_01/html/821-1451/spmonitor-22.html ...
- ubuntu下如何安装wxpython
1.运行时缺失wx库,如何安装 Error:ImportError: No module named wx 解决方法:sudo apt-get install python-wxgtk2.8 pyth ...
- Freezing Your Tuples Off 之 vacuum_freeze_min_age
The vacuum_freeze_min_age setting determines the youngest XID which will be changed to FrozenXID on ...