codeforces 600D Area of Two Circles' Intersection
生活随笔
收集整理的這篇文章主要介紹了
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[2],y[2],r[2];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)/(2*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(-1);double solve() {if(r[0] > r[1]){swap(r[0],r[1]);swap(x[0],x[1]);swap(y[0],y[1]);}ll dx = x[0]-x[1], dy = y[0]-y[1];ll ds = sqrl(dx)+sqrl(dy);if(ds >= sqrl(r[0]+r[1])) return 0;ld d = sqrtl(ds);if(d+r[0] <= r[1]) return sqr(r[0])*pi;ld ang[2];ang[0] = fcos(d,r[0],r[1]);ang[1] = fcos(d,r[1],r[0]);/*WA 28ld 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[0],r[0]) + cut(ang[1],r[1]); }//#define LOCAL int main() { #ifdef LOCALfreopen("in.txt","r",stdin); #endifcin>>x[0]>>y[0]>>r[0]>>x[1]>>y[1]>>r[1];printf("%.10f\n", solve());return 0; }?
轉載于:https://www.cnblogs.com/jerryRey/p/5003681.html
總結
以上是生活随笔為你收集整理的codeforces 600D Area of Two Circles' Intersection的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux内核笔记--内存管理之用户态进
- 下一篇: UIView 的基础