Question:
Give you n points, m Ray
Find a polygon so that the area of the polygon is divided by the number of interior mines of the polygon to the minimum value.
If you think about it, it's okay to find the triangle with the smallest ratio, because the ratio of other triangles is larger than that of the triangle. After the triangle is combined into a polygon, it is bound to increase the ratio.
Therefore, we can enumerate the triangle directly by using brute force O (n ^ 3) and calculate the ratio of the number of mines in the triangle.
If the number of record records is used, prepare an array and draw a picture.
Cnt = (point above I k)-(point above I j + point above j k)
Take the absolute value.
[Cpp]
# Include <cstdio>
# Include <cmath>
# Include <cstdlib>
# Include <algorithm>
Using namespace std;
Struct Point {
Int x, y;
Bool operator <(const Point & cmp) const {
Return x <cmp. x;
}
} P [210], mine [510];
Inline int XX (Point a, Point B, Point c ){
Return (B. x-a.x) * (c. y-a.y)-(B. y-a.y) * (c. x-a.x );
}
Int n, m;
Int num [210] [510];
Void gao (Point a, Point B, int & cnt)
{
Int x1 = a. x, x2 = B. x;
For (int I = 0; I <m; I ++) if (x1 <= mine [I]. x & mine [I]. x <x2) // pay attention to the boundary. One side is an open interval.
If (XX (a, B, mine [I])> 0)
Cnt ++;
}
Int main ()
{
Int t, ca = 1;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n, & m );
For (int I = 0; I <n; I ++) scanf ("% d", & p [I]. x, & p [I]. y );
Sort (p, p + n );
For (int I = 0; I <m; I ++) scanf ("% d", & mine [I]. x, & mine [I]. y );
For (int I = 0; I <n; I ++) for (int j = I + 1; j <n; j ++) gao (p [I], p [j], num [I] [j] = 0 );
Double ans =-1;
For (int I = 0; I <n; I ++) for (int j = I + 1; j <n; j ++) for (int k = j + 1; k <n; k ++)
{
Int cnt = num [I] [k]-num [I] [j]-num [j] [k];
If (cnt = 0) continue;
Double area = (double) XX (p [I], p [j], p [k])/2;
If (ans =-1 | fabs (area/cnt) <ans) ans = fabs (area/cnt );
}
If (ans! =-1) printf ("Case # % d: %. 6lf \ n", ca ++, ans );
Else printf ("Case # % d:-1 \ n", ca ++ );
}
Return 0;
}