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& ...
随机推荐
- Flex 确定弹出窗口的绝对位置x , y
var selectbox:Selectbox; selectbox = new SelectBox(); var pt:Point = new Point(0,0); pt = this.paren ...
- 还一道区间DP -- MZOJ 1346: 不老的传说
http://10.37.2.111/problem.php?id=1346 与上一道染色基本一样,就加了个限制条件(一次最多刷maxd) #include <bits/stdc++.h> ...
- python对数据类型的相关操作
一.int的相关操作 int只有一个相关操作,bit_length() 用于计算一个数字的二进制长度 二.bool的相关操作 1.把数字转换成bool,除了0,返回的都是True a = 10 p ...
- c#中数组array和list在函数间传递 转置
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- php,微信公众号,获取用户地理位置 定位 经纬度
<?php //php插件下载地址: https://files.cnblogs.com/files/fan-bk/jssdk_php.rar //建立一个php文件 require_once ...
- tabindex属性用法
支持tabindex属性的元素:<a> <input> <textarea> <area> <select> <button> ...
- wchar_t,char,string,wstring等的总结
一.LPSTR LPCSTR LPTSTR LPCTSTR等 确定的类型: LPSTR = CHAR * = char * LPCSTR = const CHAR * = char * //c意为co ...
- Ng第十二课:支持向量机(Support Vector Machines)(三)
11 SMO优化算法(Sequential minimal optimization) SMO算法由Microsoft Research的John C. Platt在1998年提出,并成为最快的二次规 ...
- Ng第十二课:支持向量机(Support Vector Machines)(二)
7 核函数(Kernels) 最初在“线性回归”中提出的问题,特征是房子的面积x,结果y是房子的价格.假设从样本点的分布中看到x和y符合3次曲线,那么我们希望使用x的三次多项式来逼近这些样本点.那么首 ...
- Android自定义视图三:给自定义视图添加“流畅”的动画
这个系列是老外写的,干货!翻译出来一起学习.如有不妥,不吝赐教! Android自定义视图一:扩展现有的视图,添加新的XML属性 Android自定义视图二:如何绘制内容 Android自定义视图三: ...