GPLT L3-021 altar

In the ancient city of Mindray, stand tall with God n block of stone. Discuss elders, select three Jinseki enclose an altar. Because the energy intensity and its altar area inversely proportional to the altar area as small as possible. Particularly, if there are two jinseki same coordinates, or three collinear jinseki, the area of the altar  0.000.

The elders found that the problem is not so simple, so entrust your program to solve this problem.

Input formats:

In the first line of the input is given a positive integer n-(. 3  ≤ n-  ≤ 5000). Then n lines, each line has two integers, respectively jinseki abscissa, ordinate ( - abscissa, ordinate  <).

Output formats:

The minimum area of ​​the output altar in a row, rounded to three decimal places.

Sample input:

8
3 4
2 4
1 1
4 1
0 3
3 0
1 3
4 2
 

Sample output:

0.500
 

Sample interpretation

FIG value output is equal to the area of ​​the triangle in red or purple border.

altar.JPG

Portal:

https://pintia.cn/problem-sets/994805046380707840/problems/994805046577840128

Ideas:

A computational geometry problem, to answer with a polar angle sort.

Polar angle: angle, polar angle and any sort of polar connection point is sorted according to the size of the polar angle in the plane.

Suppose there are three $ A, B, C $ (where A is the origin), the $ \ Theta _B = \ tfrac {y_B-y_A} {x_B-x_A}, \ Theta _C = \ tfrac {y_C-y_A} {x_C- x_A} $

In fact, determine $ (x_C-x_A) (y_B-y_A) $ and $ (x_B-x_A) (y_C-y_A) $ size.

We enumerate the points $ A $, to order the polar angle.

Code:

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 struct point
 7 {
 8     ll x;
 9     ll y;
10 };
11 
12 point p[5005];
13 point e[5005];
14 
15 bool cmp(point a, point b)
16 {
17     return a.x * b.y < a.y * b.x;
18 }
19 int  main()
20 
21 {
22     int n;
23     scanf("%d", &n);
24 
25     for(int i = 1; i <= n; i++)
26     {
27         scanf("%lld%lld", &p[i].x, &p[i].y);
28     }
29     double ans = 1e18;
30     for(int i = 1; i <= n; i++)
31 
32     {
33         int cnt = 0;
34         for(int j = 1; j <= n; j++)
35         {
36             if(i != j)
37             {
38                 e[cnt].x = p[i].x - p[j].x;
39                 e[cnt].y = p[i].y - p[j].y;
40                 cnt++;
41             }
42         }
43 
44         sort(e, e + cnt, cmp);
45         for(int j = 1; j <cnt; j ++ )
 46              years = min (years 1.0 abs * (e [j] .x * E [j - 1 ] .y - E [j] .y * E [j - 1 ] .x));
47      }
 48      years = years / 2.0 ;
49      printf ( " % .3lf \ n " , year);
50 }

 

Guess you like

Origin www.cnblogs.com/yyaoling/p/12363342.html