BZOJ2178: 圆的面积并(格林公式)
题面
题解
好神仙……
先给几个定义
平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域。通俗地说,单连通区域是没有“洞”的区域。
正方向:当\(xOy\)平面上的曲线起点与终点重合时,则称曲线为闭曲线。设平面的闭曲线L围成平面区域\(D\),并规定当一个人沿闭曲线\(L\)环行时,区域\(D\)总是位于此人的左侧,称此人行走方向为曲线L关于区域\(D\)的正方向,反之为负方向。
格林公式:设\(D\)是一个平面单连通区域,\(L\)是它取正向的轮廓线(分段光滑),\(P,Q\)在\(D\)上具有一阶连续偏导数,则有格林公式
\]
关于那个\(\oint\)就是一个有方向的\(\int\),直接当成\(\int\)看就好了
回到本题,我们令\(Q=x,P=-y\),我们要求的东西就是
\]
这样转化之后,我们就可以把圆的面积转化成跟轮廓线有关的计算了
因为圆弧上\(x,y\)很麻烦,我们用角度来表示它
\int\limits_L-y\mathrm dx+x\mathrm dy
&=\int\limits_L-(y_0+r\sin t)\mathrm d(x_0+r\cos t)+(x_0+r\cos t)\mathrm d(y_0+r\sin t)\\
&=\int\limits_L(y_0+r\sin t)(r\sin t)+(x_0+r\cos t)(r\cos t)\\
&=r\int\limits_L(y_0+r\sin t)\sin t+(x_0+r\cos t)\cos t\\
&=r\int\limits_L r+y_0\sin t+x_0\cos t\\
&=r^2t+x_0\sin t-y_0\cos t
\end{aligned}
\]
然后把圆弧的轮廓线搞出来做曲线积分,求和就可以了
顺便这样例太凉心了
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1005;const double Pi=acos(-1.0);
struct Point{
int x,y;
inline Point(){}
inline Point(R int xx,R int yy):x(xx),y(yy){}
inline Point operator +(const Point &b)const{return Point(x+b.x,y+b.y);}
inline Point operator -(const Point &b)const{return Point(x-b.x,y-b.y);}
inline bool operator <(const Point &b)const{return x<b.x||(x==b.x&&y<b.y);}
inline bool operator ==(const Point &b)const{return x==b.x&&y==b.y;}
inline double norm(){return sqrt(x*x+y*y);}
};
struct Cir{
Point p;int r;
inline bool operator <(const Cir &b)const{return p<b.p||p==b.p&&r<b.r;}
inline bool operator ==(const Cir &b)const{return p==b.p&&r==b.r;}
inline double oint(R double t1,R double t2){
return r*(r*(t2-t1)+p.x*(sin(t2)-sin(t1))-p.y*(cos(t2)-cos(t1)));
}
}c[N];
pair<double,int>st[N<<1];int n;double res;
double calc(int id){
int top=0,cnt=0;
fp(i,1,n)if(i!=id){
double dis=(c[i].p-c[id].p).norm();
if(c[id].r+dis<=c[i].r)return 0;
if(c[i].r+dis<=c[id].r||c[i].r+c[id].r<=dis)continue;
double del=acos((c[id].r*c[id].r+dis*dis-c[i].r*c[i].r)/(2*c[id].r*dis));
double ang=atan2(c[i].p.y-c[id].p.y,c[i].p.x-c[id].p.x);
double l=ang-del,r=ang+del;
if(l<-Pi)l+=2*Pi;if(r>=Pi)r-=2*Pi;
if(l>r)++cnt;
st[++top]=make_pair(l,1),st[++top]=make_pair(r,-1);
}
st[0]=make_pair(-Pi,0),st[++top]=make_pair(Pi,0);
sort(st+1,st+1+top);
double res=0;
for(R int i=1;i<=top;cnt+=st[i++].second)
if(!cnt)res+=c[id].oint(st[i-1].first,st[i].first);
return res;
}
int main(){
// freopen("testdata.in","r",stdin);
scanf("%d",&n);
fp(i,1,n)scanf("%d%d%d",&c[i].p.x,&c[i].p.y,&c[i].r);
sort(c+1,c+1+n),n=unique(c+1,c+1+n)-c-1;
fp(i,1,n)res+=calc(i);
printf("%.3lf\n",res*0.5);
return 0;
}
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 圆的面积并 计算几何 辛普森积分
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...
- bzoj2178: 圆的面积并
Description 给出N个圆,求其面积并 Input 先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数 Output 面积并,保留三位小数 ...
- 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& ...
随机推荐
- 利用 FFmpeg 将 MP4 转成 FLV
最近做一个小项目,要在线播放录制的 MP4 视频,想开源的 flash player 或 html 5 可以播放.可,虽然 MP4 是 H.264 编码,但就是播放不了.可能是封装方式(PS 方式)不 ...
- 【Web】Sublime Text 3 连接sftp/ftp(远程服务器)
在 Win 下常用 Xftp 软件来和远程服务传递文件,但是要是在项目开发的时候频繁的将远程文件拖到本地编辑然后再传回远程服务器,那真是麻烦无比,但是Sublime中SFTP插件,它让这世界美好了许多 ...
- PHP函数可变参数
PHP自定义函数中支持可变数量的参数 在PHP 5.5 及更早的版本中,使用函数func_num_args() , func_get_arg() , func_get_args()实现: 我们举个例子 ...
- java JNI 实现原理 (二) Linux 下如何 load JNILibrary
在博客java JNI (一)虚拟机中classloader的JNILibrary 中讨论了java中的Library 是由classloader 来load的,那我们来看看 classloader是 ...
- vue组件实现查看大图效果
使用的index.vue代码 <template> <img :src="imgUrl" @click="clickImg($event)"& ...
- 2019.01.04 洛谷P4719 【模板】动态dp(链分治+ddp)
传送门 ddpddpddp模板题. 题意简述:给你一棵树,支持修改一个点,维护整棵树的最大带权独立集. 思路: 我们考虑如果没有修改怎么做. 貌似就是一个sbsbsb树形dpdpdp,fi,0f_{i ...
- 2018.11.07 NOIP训练 lzy的游戏(01背包)
传送门 考虑对于每次最后全部选完之后剩下的牌的集合都对应着一种构造方法. 一个更接地气的说法: 设消耗的牌数为ttt,如果使用的牌的lll值之和也为ttt,则对应着一种构造方式让这种情形成立. 于是做 ...
- 5-具体学习git--分支冲突,merge合并
修改1.py: 然后提交修改: git commit -am "change 4 in master" 之后移到dev分支上: 哎呀,这个乱了. 人家意思是都基于c1分出来两个枝, ...
- UVa 11542 Square (高斯消元)
题意:给定 n 个数,从中选出一个,或者是多个,使得选出的整数的乘积是完全平方数,求一共有多少种选法,整数的素因子不大于 500. 析:从题目素因子不超过 500,就知道要把每个数进行分解.因为结果要 ...
- 好文推荐系列---------(4)使用Yeoman自动构建Ember项目
好文原文地址:http://segmentfault.com/a/1190000000368881 我决定学习前端开发的效率工具Yeoman.本文将首先介绍Yeoman的基本情况,接着我们会使用Yeo ...