POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)
题目链接:
id=2546
ZOJ: problemId=597" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597
Description
Input
Output
Sample Input
20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
608.366
Source
题意:
求两圆相交的面积!
直接上模板
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
//#include <complex>
//#include <iomanip>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0); int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0) return - 1;
else return 1;
}
struct Point
{
double x, y;
Point(){}
Point(double _x, double _y)
{
x = _x; y = _y;
}
Point operator -( const Point &b) const
{
return Point(x - b. x, y - b. y);
}
//叉积
double operator ^ (const Point &b) const
{
return x*b. y - y*b. x;
}
//点积
double operator * (const Point &b) const
{
return x*b. x + y*b. y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x = tx* cos(B) - ty*sin(B);
y = tx* sin(B) + ty*cos(B);
}
};
//*两点间距离
double dist( Point a, Point b)
{
return sqrt((a-b)*(a- b));
}
//两个圆的公共部分面积
double Area_of_overlap(Point c1, double r1, Point c2, double r2)
{
double d = dist(c1,c2);
if(r1 + r2 < d + eps) return 0;
if(d < fabs(r1 - r2) + eps)
{
double r = min(r1,r2);
return PI*r*r;
}
double x = (d*d + r1*r1 - r2*r2)/(2*d);
double t1 = acos(x / r1);
double t2 = acos((d - x)/r2);
return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
} int main()
{
double x1, y1, r1, x2, y2, r2;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))
{
Point c1, c2;
c1.x = x1;
c1.y = y1;
c2.x = x2;
c2.y = y2;
double ans = Area_of_overlap(c1,r1,c2,r2);
printf("%.3lf\n",ans);
//cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;
}
return 0;
}
POJ 2546 & ZOJ 1597 Circular Area(求两圆相交的面积 模板)的更多相关文章
- 求两圆相交部分面积(C++)
已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- poj2546Circular Area(两圆相交面积)
链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...
- POJ 2546 Circular Area(两个圆相交的面积)
题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...
- 两圆相交求面积 hdu5120
转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...
- [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点
POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...
- ZOJ 1280 Interesting Lines | 求两直线交点
原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...
- UVa 10674 (求两圆公切线) Tangents
题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...
随机推荐
- 【BZOJ】1095: [ZJOI2007]Hide 捉迷藏 括号序列+线段树
[题目]BZOJ 1095 [题意]给定n个黑白点的树,初始全为黑点,Q次操作翻转一个点的颜色,或询问最远的两个黑点的距离,\(n \leq 10^5,Q \leq 5*10^5\). [算法]括号序 ...
- 记录下(同一个计算机)多个容器 dockr bridge(桥接) docker-compose 配置
直接上 version: '3' services: mysql: container_name: mysql image: mysql:5.7.21 environment: MYSQL_ROOT_ ...
- 第8月第21天 django lbforum项目记录
1. django-admin.py startproject lbforum01 ls cd lbforum01/ ls python manage.py startapp forum sudo p ...
- 关于Mysql5.6半同步主从复制的开启方法【转】
介绍 先了解一下mysql的主从复制是什么回事,我们都知道,mysql主从复制是基于binlog的复制方式,而mysql默认的主从复制方式,其实是异步复制. 主库实际上并不关心从库是否把数据拉完没有, ...
- Codeforces 600E - Lomsat gelral 「$Dsu \ on \ tree$模板」
With $Dsu \ on \ tree$ we can answer queries of this type: How many vertices in the subtree of verte ...
- Qt 程序等待多长时间执行Sleep
#include <QTime> void MainWindow::Sleep(unsigned int msec) { QTime reachTime=QTime::currentTim ...
- idea如何编译maven项目
这里我们介绍两种方式,如何调试出窗口 点击菜单栏View->Tool Windows->Maven projects 点击菜单栏Help->Find Action(Ctrl+Shi ...
- 使用Eclipse运行第一个Go程序
Windows 10家庭中文版,go version go1.11 windows/amd64, Eclipse IDE for C/C++ Developers Photon Release (4. ...
- mybatis SQL构造器
org.apache.ibatis.jdbc.AbstractSQL<T> org.apache.ibatis.jdbc.AbstractSQL<T> 抽象泛型类,它主要用于解 ...
- java 异常匹配
抛出异常的时候,异常处理系统会安装代码书写顺序找出"最近"的处理程序. 找到匹配的程序后,它就认为异常将得到清理,然后就不再继续查找. 查找的时候并不要求抛出的异常同处理程序的异常 ...