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 ...
随机推荐
- JAVA之反射(一)
反射(一) ** 注:博主的这篇文章是在学习反射的时间写的如有问题请及时联系博主进行修改 ** 何为反射 这里也不说一些很官方的语言了,官方的说明看着头痛,总之一句话,就是在JAVA的运行状态的时候 ...
- HTML常用标签与CSS基础知识
一.HTML页面结构 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- IdentityServer4 学习笔记[1]-客户端授权
前言 本文内容来自IdentityServer4官网,官网有详细的介绍,并且有源码Demo 官网源码例子传送门 建立授权服务端 我们暂时不配置Https,选择空模板建立项目,项目建立后, 为了查看de ...
- Docker Flie
七.Docker File .dockeringore:打包忽略的文件列表,每行写一个文件的路径,可使用通配符 FROM指令:指定基础镜像 FROM <repository>[:<t ...
- 小K的农场 差分约束
题目描述 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述: 农场a比农场b至少多种植了c个单位的作 ...
- Django基础(3)----模型层-单表操作,多表创建
昨日内容回顾: 1. {% include '' %} 2. extend base.html: <html> ..... ..... ..... {% block content%} { ...
- LeetCode 208 Implement Trie (Prefix Tree) 字典树(前缀树)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are ...
- hide(),show()
var newstypevalue =$("#newstype option:selected").val(); if(newstypevalue=='0'){ ...
- 查看Memcache运行状况
Memcache Memcache是danga.com的一个开源项目,它是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的Hash表,能够用来存储各种格式的数据. 查看当前的me ...
- pat1069. The Black Hole of Numbers (20)
1069. The Black Hole of Numbers (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, ...