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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【CodeForces - 340B 】Maximal Area Quadrilateral (计算几何,枚举,有坑)

發(fā)布時(shí)間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 340B 】Maximal Area Quadrilateral (计算几何,枚举,有坑) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

Iahub has drawn a set of?n?points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.

Input

The first line contains integer?n?(4?≤?n?≤?300). Each of the next?n?lines contains two integers:?xi,?yi?(?-?1000?≤?xi,?yi?≤?1000)?— the cartesian coordinates of?ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.

Output

Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed?10?-?9.

Examples

Input

5 0 0 0 4 4 0 4 4 2 3

Output

16.000000

Note

In the test example we can choose first?4?points to be the vertices of the quadrilateral. They form a square by side?4, so the area is?4·4?=?16.

題目大意:

? ?給你n個點(diǎn),讓你從這些點(diǎn)里面尋找4個點(diǎn),使得四邊形的面積最大。當(dāng)然題目說了沒有三個點(diǎn)在一條線上,沒有重合的點(diǎn)。

解題報(bào)告:

? ?這題看起來不難啊,,把四個點(diǎn)拆成兩個三角形然后枚舉2+1+1,三重循環(huán)就搞定了,,但是這題還是很坑的啊,,WA23的同黨肯定不少吧,,看這個簡單的B題當(dāng)時(shí)cf比賽的時(shí)候比D過題的人都少(不過也可能因?yàn)檫@場的D確實(shí)簡單,看懂了就是個模板題)

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; const double eps = 1e-8; int sgn(double x) {if(fabs(x) < eps)return 0;if(x < 0) return -1;return 1; } struct Point {double x,y;int id;Point() {}Point(double x,double y):x(x),y(y) {}Point operator -(const Point &b)const {return Point(x - b.x,y - b.y);}double operator ^(const Point &b)const {return x*b.y - y*b.x;}double operator *(const Point &b)const {return x*b.x + y*b.y;} } p[1005]; double ans,ans1,ans2; int main() {int n;cin>>n;for(int i = 1; i<=n; i++) scanf("%lf%lf",&p[i].x,&p[i].y),p[i].id = i;for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {ans1=ans2=-1.0;for(int k = 1; k<=n; k++) {if(k == i || k == j) continue;double tmp = (p[k]-p[i])^(p[j]-p[i]); if(sgn(tmp) > 0) ans1 = max(ans1,tmp);if(sgn(tmp) < 0) ans2 = max(ans2,-tmp);}if(ans1==-1.0 || ans2 == -1.0) continue;//這么用還是小心點(diǎn)、、、 // cout << i << "***"<<j<< "***"; // cout << ans1+ans2<<endl;ans = max(ans,ans1+ans2);}}printf("%.8f\n",ans/2);return 0 ;} /* 4 0 0 0 5 5 0 1 1 */

總結(jié):

? sgn函數(shù)要用啊,,,double別直接等號判斷,,很危險(xiǎn)、、

? ?這是個坑啊,,還是自己太不小心了、、

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 340B 】Maximal Area Quadrilateral (计算几何,枚举,有坑)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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