codeforces D. Area of Two Circles' Intersection 计算几何
2 seconds
256 megabytes
standard input
standard output
You are given two circles. Find the area of their intersection.
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109) — the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109) — the position of the center and the radius of the second circle.
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed10 - 6.
0 0 4
6 0 4
7.25298806364175601379
0 0 5
11 0 5
0.00000000000000000000
题意:求两个圆相交面积,主要问题就是精度的问题;
解决思路:在两个圆心相距很远的时候用两个圆心和一个交点算角度的精度可能不够,可以用两个交点和一个圆心来算比较好;
AC代码:
#include <bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;
long double x1,x2,y2,r1,r2,y;
long double area(){
long double d=sqrt((x1-x2)*(x1-x2)+(y-y2)*(y-y2));
if(r1>r2){
long double temp=r1;
r1=r2;
r2=temp;
}
if(r1+r2<=d) return 0;
else if(r2-r1>=d) return pi*r1*r1;
else {
long double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
long double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
a1*=2;
a2*=2;
return (a1*r1*r1+a2*r2*r2-r1*r1*sin(a1)-r2*r2*sin(a2))/2.0;
}
}
int main()
{
cin>>x1>>y>>r1;
cin>>x2>>y2>>r2;
cout<<fixed<<area()<<endl; return 0;
}
codeforces D. Area of Two Circles' Intersection 计算几何的更多相关文章
- codeforces 600D Area of Two Circles' Intersection
分相离,内含,想交三种情况讨论一下. 主要是精度和数据范围的问题,首先数据用long double,能用整型判断就不要用浮点型. 题目中所给的坐标,半径是整型的,出现卡浮点判断的情况还是比较少的. 最 ...
- codeforce--600D - Area of Two Circles' Intersection
题意:求相交圆的面积.借鉴大神代码,精度超高. #include <fstream> #include <iostream> #include <string> # ...
- SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)
Description You are given N circles and expected to calculate the area of the union of the circles ! ...
- Intersection(计算几何)
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)To ...
- hdu-5120 Intersection(计算几何)
题目链接: Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Ot ...
- POJ 1410 Intersection (计算几何)
题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- Codeforces Round #465 &935C. Fifa and Fafa计算几何
传送门 题意:在平面中,有一个圆,有一个点,问能在这个圆中围出最大的圆的圆心坐标和半径.要求这个最大圆不包含这个点. 思路:比较基础的计算几何,要分三种情况,第一种就是这个点在圆外的情况.第二种是点在 ...
- codeforces#1163C2. Power Transmission (Hard Edition)(计算几何)
题目链接: https://codeforces.com/contest/1163/problem/C2 题意: 给出$n$个点,任意两点连接一条直线,求相交直线的对数 数据范围: $1 \le n ...
随机推荐
- 和openjdk在一起的第一天-第一次接触有些生疏,就先熟悉一下吧
暂时搞到了openjdk7,就将就着看吧,(为什么csdn全部都是收费啊,llllj),但是还是决定先读这个openjdk7 还有,不知道怎么的就想试试markdown,也不知道好用不 hello w ...
- R&python机器学习之朴素贝叶斯分类
朴素贝叶斯算法描述应用贝叶斯定理进行分类的一个简单应用.这里之所以称之为“朴素”,是因为它假设各个特征属性是无关的,而现实情况往往不是如此. 贝叶斯定理也称贝叶斯推理,早在18世纪,英国学者贝叶斯(1 ...
- Shell字符串操作
@1:子串削除 ${string#substring} 从$string 的开头位置截掉最短匹配的$substring. ${string##substring} 从$string 的开头位置截掉最长 ...
- css字体样式
css字体样式(Font Style) 属性 css文本样式 序号 中文说明 标记语法 1 字体样式 {font:font-style font-variant font-weight f ...
- jQuery:自学笔记(5)——Ajax
jQuery:自学笔记(5)——Ajax 使用Ajax快捷函数 说明 出于简化AJAX开发工作的流程,jQuery提供了若干了快捷函数. 实例 1.显示 test.php 返回值(HTML 或 XML ...
- vue(组件、路由)懒加载
const Login = resolve => require(['@/components/Login'], resolve) //就不用import了 Vue.use(Router) le ...
- 【leetcode刷题笔记】Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- I.MX6Q(TQIMX6Q/TQE9)学习笔记——U-Boot移植
其实Freescale的BSP移植文档已经将u-boot的移植步骤讲述的非常详细了,但为了以后方便查阅,还是按照自己的理解记录在这里. 获取源码 根据前一篇文章搭建好LTIB环境后就可以非常方便的导出 ...
- RHCE学习笔记 管理1 (第一、二章)
第一章 命令行访问 1.Ctrl+alt+F2~F6 切到虚拟控制台,ctrl+alt+F1 回到图形界面 2.格式 : 命令 选项 参数 [] 为可选项目 ...表示该项目任意 ...
- Mybatis细节问题
1.将字符串转换为日期格式? @DateTimeFormat(pattern="yyyy-MM-dd")