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 ...
随机推荐
- NumPy基础知识:数组和矢量计算
NumPy 的ndarray:一种多维数组对象 该对象是一个快速且灵活的大数据容器,可以利用这种数组对整个数据进行科学计算,语法跟标量元素之间的计算一样. 创建ndarray的方法: array函数: ...
- python之路:进击的小白
1.hello world print("hello world") 2.变量定义的规则 变量名只能是 字母.数字或下划线的任意组合 变量名的第一个字符不能是数字 以下关键字不能声 ...
- PHP用星号隐藏部份用户名、身份证、IP、手机号、邮箱等实例
一.仿淘宝评论购买记录隐藏部分用户名,以下代码亲测可用. function cut_str($string, $sublen, $start = 0, $code = 'UTF-8') { if( ...
- 动手动脑:String.equals()的使用方法
public class StringEquals { /** * @param args the command line arguments */ public static void main( ...
- 每天一个Linux命令(57)rpm命令
rpm是一个功能十分强大的软件包管理系统. (1)用法: 用法: rpm [参数] [包名] (2)功能: 功能: 使得在Linux下安装.升级和删除软 ...
- Linux Shell编程 循环语法
for循环 for 循环是固定循环,也就是在循环时已经知道需要进行几次循环.有时也把 for 循环称为计数循环.语法: for 变量 in 值1 值2 值3… do 程序 done 在这种语法中,fo ...
- 树莓派连接DHT11温湿度传感器(python)
介绍 DHT11作为一个廉价配件,同时包含了温度.湿度传感器,而且,编码使用也非常简单. 本文介绍如果在树莓派中使用 DHT11,代码是Python.如果有任何疑问,欢迎在下面留言. 接线 VCC接5 ...
- BEM(一种 CSS 命名规则)
一. 什么是 BEM BEM的意思就是块(block).元素(element).修饰符(modifier),是由 Yandex 团队提出的一种前端命名方法论. 这种巧妙的命名方法让你的 CSS 类对其 ...
- Qt5.2.1交叉编译,带tslib插件
一: 源码下载地址: 1.1: 平台: 主机:ubuntu 14.04 开发板: cpu arm-cortex-a8,故而我在配置我的qmake.conf的时候填写的为armV7-a QT版本: qt ...
- html5-entities.js消失问题
今天用nuxt做项目时,启动npm run dev,项目正常启动, 可过一会儿再试图启动时却报错: * ./libhtml5-entities.js in ./~/html-entities/inde ...