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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LA 2402 (枚举) Fishnet

發(fā)布時間:2024/1/17 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LA 2402 (枚举) Fishnet 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題意:

正方形四個邊界上分別有n個點,將其劃分為(n+1)2個四邊形,求四邊形面積的最大值。

分析:

因為n的規(guī)模很小,所以可以二重循環(huán)枚舉求最大值。

求直線(a, 0) (b, 0) 和直線(0, c) (0, d)的交點,我是二元方程組求解得來的,然后再用叉積求面積即可。

1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 6 const int maxn = 30 + 10; 7 struct HEHE 8 { 9 double a, b, c, d; 10 }hehe[maxn]; 11 12 struct Point 13 { 14 double x, y; 15 Point(double x=0, double y=0):x(x), y(y) {} 16 }; 17 typedef Point Vector; 18 19 Vector operator - (const Vector& A, const Vector& B) 20 { return Vector(A.x - B.x, A.y - B.y); } 21 22 double Cross(const Vector& A, const Vector& B) 23 { return (A.x*B.y - A.y*B.x); } 24 25 Point GetIntersection(const double& a, const double& b, const double& c, const double& d) 26 { 27 double x = (a+(b-a)*c) / (1-(b-a)*(d-c)); 28 double y = (d-c)*x+c; 29 return Point(x, y); 30 } 31 32 int main(void) 33 { 34 //freopen("2402in.txt", "r", stdin); 35 36 int n; 37 while(scanf("%d", &n) == 1 && n) 38 { 39 memset(hehe, 0, sizeof(hehe)); 40 for(int i = 1; i <= n; ++i) scanf("%lf", &hehe[i].a); 41 for(int i = 1; i <= n; ++i) scanf("%lf", &hehe[i].b); 42 for(int i = 1; i <= n; ++i) scanf("%lf", &hehe[i].c); 43 for(int i = 1; i <= n; ++i) scanf("%lf", &hehe[i].d); 44 hehe[n+1].a = hehe[n+1].b = hehe[n+1].c = hehe[n+1].d = 1.0; 45 46 double ans = 0.0; 47 for(int i = 0; i <= n; ++i) 48 for(int j = 0; j <= n; ++j) 49 { 50 Point A, B, C, D; 51 A = GetIntersection(hehe[i].a, hehe[i].b, hehe[j].c, hehe[j].d); 52 B = GetIntersection(hehe[i+1].a, hehe[i+1].b, hehe[j].c, hehe[j].d); 53 C = GetIntersection(hehe[i+1].a, hehe[i+1].b, hehe[j+1].c, hehe[j+1].d); 54 D = GetIntersection(hehe[i].a, hehe[i].b, hehe[j+1].c, hehe[j+1].d); 55 double temp = 0.0; 56 temp += Cross(B-A, C-A) / 2; 57 temp += Cross(C-A, D-A) / 2; 58 ans = std::max(ans, temp); 59 } 60 61 printf("%.6f\n", ans); 62 } 63 64 return 0; 65 } 代碼君

?

轉(zhuǎn)載于:https://www.cnblogs.com/AOQNRMGYXLMV/p/4148827.html

總結(jié)

以上是生活随笔為你收集整理的LA 2402 (枚举) Fishnet的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。