1. 程式人生 > >【中山市選2013】蓄養

【中山市選2013】蓄養

Description

平面上有N顆樹,標號從1到N,每顆樹有座標(Xi, Yi)。要求在平面上找幾棵樹,在一些樹之間建籬笆形成一個閉合圖形(籬笆不能在除了樹以外的地方相交,形成的圖形面積不能為0).求最小可能圍成的面積。

Input

第一行輸入N。

然後N行第i行輸入第i棵樹的座標Xi和Yi。

Output

輸出最小圍成的面積,小數點後保留兩位小數。無解輸出“Impossible”

Sample Input

4

-1.00 0.00

0.00 -3.00

2.00 0.00

2.00 2.00

Sample Output

2.00

Data Constraint

對於40%資料 1 ≤ N ≤ 20

對於所有資料 1 ≤ N ≤ 100,-1000 ≤ Xi,Yi ≤ 1000

思路:

超級水的題啊!!!
列舉三個點,用叉積求面積,O(n^3)過。

程式碼:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
struct F
{

    double x,y;

}t[111];
double cj(F a,F b,F c)
{

    return abs((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));

}
double ans=2147483647
; int main() { int n=0; scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%lf%lf",&t[i].x,&t[i].y); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) for(int k=1; k<=n; k++) if(i!=j && j!=k && i!=k) if (cj(t[i],t[j],t[k])!=0) ans=min(ans,cj(t[i],t[j],t[k])); if
(ans!=2147483647) printf("%.2lf",ans/2);else printf("Impossible"); }