Educational Codeforces Round 2D. Area of Two Circles' Intersection(计算几何+圆相交的面积)
2015-11-29 16:37
441 查看
题目链接
题意:计算圆的相交面积
解法:模板来一发,但是坑的是,精度。用long double ,cout.precision(9);设置输出精度9位
题意:计算圆的相交面积
解法:模板来一发,但是坑的是,精度。用long double ,cout.precision(9);设置输出精度9位
#define CF #ifndef CF #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #else #include<bits/stdc++.h> #endif // CF using namespace std; #define LL long long #define pb push_back #define X first #define Y second #define cl(a,b) memset(a,b,sizeof(a)) typedef pair<long long ,long long > P; const int maxn=2*100005; const LL inf=1LL<<50; const LL mod=1e9+7; typedef long double db; const db pi=acos(-1.0); db Deg2Rad(db deg){return (deg*pi/180.0);} db Rad2Deg(db rad){return (rad*180.0/pi);} db Sin(db deg){return sin(Deg2Rad(deg));} db ArcSin(db val){return Rad2Deg(asin(val));} db ArcCos(db val){return Rad2Deg(acos(val));} struct circle{ db x,y,r; circle(){} circle(db _x,db _y, db _r):x(_x),y(_y),r(_r){} }; struct point{ db x,y; point(){x=y=0;} point(db a,db b){ x=a,y=b; } }; point Center(const circle&c){ return point(c.x,c.y); } db Distance(const point&a,const point&b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } db Area(const circle& x){ return pi*x.r*x.r; } db commonArea(const circle&A,const circle &B){ db area=0.0; const circle&M=(A.r>B.r)?A:B; const circle&N=(A.r>B.r)?B:A; db D=Distance(Center(M),Center(N)); if((D<M.r+N.r)&&(D>M.r-N.r)){ db cosM=(M.r*M.r+D*D-N.r*N.r)/(2.0*M.r*D); db cosN=(N.r*N.r+D*D-M.r*M.r)/(2.0*N.r*D); db alpha=2.0*ArcCos(cosM); db beta= 2.0*ArcCos(cosN); db TM=0.5*M.r*M.r*Sin(alpha); db TN=0.5*N.r*N.r*Sin(beta); db FM=(alpha/360.0)*Area(M); db FN=(beta/360.0)*Area(N); area=FM+FN-TM-TN; } else if(D<=M.r-N.r){ area=Area(N); } return area; } int main(){ db x1,x2,y1,y2,r1,r2; cin>>x1>>y1>>r1; cin>>x2>>y2>>r2; circle A(x1,y1,r1),B(x2,y2,r2); cout.precision(9); cout<<commonArea(A,B)<<endl; return 0; }
相关文章推荐
- MongoDB 数据库命令操作
- HDU 5587:Array
- memcached telnet命令
- C++底层数据结构实现
- HDU 5587:Array
- jquery图片查看插件,支持旋转、放大、缩小、拖拽、缩略图(仿qq图片查看)
- 一步一步 搞定RSA(公钥、私钥)
- Android项目文件构成(Eclipse示例)
- 纯CSS气泡效果
- Android项目文件构成(Eclipse示例)
- iOS 自动布局 Masonry
- 模型作品展示帖
- imageNamed 、imageWithContentsOfFile、 initWithContentsFile区别
- [C++]文件的写入格式与输入输出流
- 罗马数字规则
- 罗马数字规则
- Android学习笔记-SQLite和Content Provider
- Signal Brief
- 矩阵乘法
- android ViewPager嵌套PhotoView报错的解决办法