题干:
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个点,让你从这些点里面寻找4个点,使得四边形的面积最大。当然题目说了没有三个点在一条线上,没有重合的点。
解题报告:
这题看起来不难啊,,把四个点拆成两个三角形然后枚举2+1+1,三重循环就搞定了,,但是这题还是很坑的啊,,WA23的同党肯定不少吧,,看这个简单的B题当时cf比赛的时候比D过题的人都少(不过也可能因为这场的D确实简单,看懂了就是个模板题)
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;//这么用还是小心点、、、
// 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
*/
总结:
sgn函数要用啊,,,double别直接等号判断,,很危险、、
这是个坑啊,,还是自己太不小心了、、