codeforces 600D Area of Two Circles' Intersection
分相离,内含,想交三种情况讨论一下。
主要是精度和数据范围的问题,首先数据用long double,能用整型判断就不要用浮点型。
题目中所给的坐标,半径是整型的,出现卡浮点判断的情况还是比较少的。
最后算三角型面积的时候不要用海伦公式,有四个连乘很容易爆数据范围损失精度,即使拆开两两乘也要考虑符号
(取对数也是比较好的办法)。(不知道sqrt和cos,sin的精度如何比较
#include<bits/stdc++.h>
using namespace std; typedef long double ld;
typedef long long ll; ld x[],y[],r[]; inline ld sqr(ld x){ return x*x; }
inline ll sqrl(ll x) { return x*x; }
inline ld fcos(ld a, ld b, ld c)
{
return acosl((a*a+b*b-c*c)/(*a*b));
} inline ld cut(ld ang, ld r)
{
ld s1 = ang*r*r;
ld s2 = sinl(ang)*cosl(ang)*r*r;
return s1 - s2;
} const ld pi = acosl(-); double solve()
{
if(r[] > r[]){
swap(r[],r[]);
swap(x[],x[]);
swap(y[],y[]);
}
ll dx = x[]-x[], dy = y[]-y[];
ll ds = sqrl(dx)+sqrl(dy);
if(ds >= sqrl(r[]+r[])) return ;
ld d = sqrtl(ds);
if(d+r[] <= r[]) return sqr(r[])*pi; ld ang[];
ang[] = fcos(d,r[],r[]);
ang[] = fcos(d,r[],r[]);
/*
WA 28
ld area = ang[1]*sqr(r[1]) + ang[0]*sqr(r[0]);
ld s = (d+r[0]+r[1])/2;
area -= sqrtl(s*(s-d)*(s-r[0])*(s-r[1]))*2; // O(n^4) 拆分会有符号问题 对数也许可行
return area;
*/
return cut(ang[],r[]) + cut(ang[],r[]);
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
cin>>x[]>>y[]>>r[]>>x[]>>y[]>>r[];
printf("%.10f\n", solve());
return ;
}
codeforces 600D Area of Two Circles' Intersection的更多相关文章
- codeforces D. Area of Two Circles' Intersection 计算几何
D. Area of Two Circles' Intersection time limit per test 2 seconds memory limit per test 256 megabyt ...
- codeforce--600D - Area of Two Circles' Intersection
题意:求相交圆的面积.借鉴大神代码,精度超高. #include <fstream> #include <iostream> #include <string> # ...
- codeforces 630P. Area of a Star
题目链接 圆上n个点等距离分布, 求构成的星星的面积. 我们可以求三角形OAB的面积, ∠CAE = 1/2 ∠ COE = PI/n, 那么∠CAO = PI/2n, ∠AOB非常好求, 就是PI/ ...
- Educational Codeforces Round 2
600A - Extract Numbers 20171106 字符串处理题,稍微注意点细节就能水过 #include<stdlib.h> #include<stdio.h&g ...
- codeforces 几道题目
BZOJ挂了....明天就要出发去GDKOI了....不能弃疗. 于是在cf水了几道题, 写写详(jian)细(dan)题解, 攒攒RP, 希望GDKOI能好好发挥....... 620E. New ...
- Trilateration三边测量定位算法
转载自Jiaxing / 2014年2月22日 基本原理 Trilateration(三边测量)是一种常用的定位算法: 已知三点位置 (x1, y1), (x2, y2), (x3, y3) 已知未知 ...
- Shape comparison language
形状比较语言, 九交模型 In this topic About shape comparison language Dimensionality Extensions to the CBM SC ...
- HDU 1724 Ellipse(数值积分の辛普森公式)
Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...
- A Statistical View of Deep Learning (IV): Recurrent Nets and Dynamical Systems
A Statistical View of Deep Learning (IV): Recurrent Nets and Dynamical Systems Recurrent neural netw ...
随机推荐
- kolla制作过程中:neutron-sfc-agent 报错的问题
在使用二进制方式编译镜像的时候,neutron的sfc-agent提示如下错误ERROR:kolla.image.build:neutron-sfc-agent Failed with status: ...
- 远程控制Ubuntu系统小结
一.在远程控制的Ubuntu上,按shift键总会出现中文字符 因为在Ubuntu中,默认启动搜狗输入法,导致在按shift键时,不停出现中文字符 一开始以为是因为远程控制,在主控机和被控机的输入法之 ...
- RabbitMQ简介和使用
一.RabbitMQ简介 1.什么是RabbitMQ AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设 ...
- springmvc json 简单例子
1.控制器层: @RequestMapping("/json.do") @ResponseBody //将会把返回值 转换为json对象 public List<User&g ...
- Git Remote (转)
基本使用 git是一个分布式代码管理工具,所以可以支持多个仓库,在git里,服务器上的仓库在本地称之为remote. 直接clone一个仓库: $: git clone git@search.ued. ...
- Meissel Lehmer Algorithm 求前n个数中素数个数 【模板】
Count primes Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- EIGRP-5-EIGRP数据包格式
EIGRP数据包直接承戟在IP数据包中.协议号为88.EIGRP数据包的最大长度取决于具体接口上的最大IP MTU设置——通常完整IP数据包为1500字节.其中1480字节可以用于 EIGRP数据包. ...
- 关于JSON可能出现的错误,待更/todo
今天写到webAppService.js的时候,用fs模块调用json,发现单引号的json被警告了. json就是一段有格式的字符串,如果数据的封装与解析都是我们自己做的时候,单引号和双引号是没啥关 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online number number number
题意:求n个斐波那契数列组合都无法得到的最小数字 解法: 1 我们先暴力的求出前面几个数字 2 然后再暴力的求递推 3 接着矩阵快速幂(没写错吧?) /*#include<bits/stdc++ ...
- inode与block
1. inode 是索引节点,在每个Linux存储设备或者存储设备的分区被格式化为ext4文件系统,一般生成两个部分:第一部分为inode,第二部分为block inode:存放的是 ...