日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU5120 - Intersection

發布時間:2023/12/3 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU5120 - Intersection 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

HDU5120 - Intersection


做法:答案就是\(A1 \cap B1 - A2 \cap B1 - A1 \cap B2 + A2 \cap B2\),圓形面積交碼了好久,先把兩個圓轉到x軸上,大的放到原點,小的放在大圓的左邊,計算一下交點坐標,然后討論即可。

#include <bits/stdc++.h> #define pb push_back typedef long long ll; const double eps = 1e-10; const double PI = acos(-1.0); using namespace std; int sgn(double x) {if(fabs(x) < eps) return 0;if(x < 0) return -1;return 1; } int n; struct cir{double x,y,r;cir(){}cir(double _x,double _y,double _r) {x=_x; y=_y; r=_r;}void output() {cout << x <<' '<< y <<' '<< r << endl;} }a1, a2, b1, b2; double dis(double ax,double ay,double bx,double by) {return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by)); } double area_t(double a,double b,double c) {if(a+b <= c) return 0;if(a+c <= b) return 0;if(c+b <= a) return 0;if(abs(a-b) >= c) return 0;if(abs(c-b) >= b) return 0;if(abs(a-c) >= a) return 0;double p = (a+b+c)*0.5;return sqrt((p-a)*(p-b)*(p-c)*p); } void chg(cir &a, cir &b) {if(a.r < b.r) swap(a,b);double D = dis(a.x,a.y,b.x,b.y);a.x = a.y = 0;b.x = D; b.y = 0; } double cal(cir a, cir b) {chg(a, b);double D = dis(a.x,a.y,b.x,b.y), ans = 0;if(sgn(D- (a.r+b.r))>= 0) return 0;if(sgn(a.r-b.r-D)>=0) return PI*b.r*b.r;double cx = (a.r*a.r + D*D - b.r*b.r)*0.5/D;double cy = sqrt(a.r*a.r - cx*cx);if(sgn(cx - b.x) <= 0) {double S1 = D*cy;double tha = asin(cy/a.r)*2;double thb = asin(cy/b.r)*2;double Sa = a.r*a.r*tha*0.5;double Sb = b.r*b.r*thb*0.5;ans = Sa + Sb - S1;}else {double tha = asin(cy/a.r)*2;double thb = 2*PI-asin(cy/b.r)*2;double Sa = a.r*a.r*tha*0.5 - area_t(a.r,a.r,cy*2);double Sb = b.r*b.r*thb*0.5 + area_t(b.r,b.r,cy*2);ans = Sa + Sb;}return ans; } int T, CC = 0; int main() {scanf("%d",&T);while(T--) {double r,R,tx1,tx2,ty1,ty2;scanf("%lf%lf",&r,&R);scanf("%lf%lf",&tx1,&ty1);scanf("%lf%lf",&tx2,&ty2);a1 = cir(tx1,ty1,R);a2 = cir(tx1,ty1,r);b1 = cir(tx2,ty2,R);b2 = cir(tx2,ty2,r);double ans = cal(a1,b1) - cal(a2,b1) - cal(a1,b2) + cal(a2,b2);printf("Case #%d: %.6f\n",++CC,ans);} }

轉載于:https://www.cnblogs.com/RRRR-wys/p/9710574.html

總結

以上是生活随笔為你收集整理的HDU5120 - Intersection的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。