"Title description"
2 dimensional plane on the surface there are N stakes, Huang Long have a chance to land and get circled to the Earth, in order to reflect his sharp sense, he will make his circle to the land area as small as possible. The enclosure requires a polygon of at least 3 points, the vertex of the polygon is a stake, and the land that is circled is the land within the polygon. (Because Huang is very god, so he allows to circle the nth point collinear, so the area is counted 0)
"Input Format"
The first line is an integer n, which indicates the number of stakes.
Next n rows, 2 integers per line represent the coordinates of a stake, and coordinate 22 is different.
"Output Format"
Only one row, which represents the smallest land area to be circled, retains 2 decimal places.
"Sample Input"
Example 1:
3
0 0
0 1
1 0
Example 2:
4
0 0
0 1
0 2
1 1
"Sample Output"
Example 1:
0.50
Example 2:
0.00
"Data Range"
For 10% of data,n<=100;
For 30% of data,n<=300;
For 50% of data,n<=500;
For 100% of data, n<=1000.
Solution
I messed up the problem. = =
Violence n^3 not much to say. But there are a lot of times when the situation is useless. So we divide these points into sqrt (n) blocks, violence within the block, relaxed and happy.
This is not a reliable way, so we can rotate the coordinate system randomly, Rand forty or fifty times can be the water over the problem.
The author's question:
Obviously, this time the violent enumeration wouldT. So we change our mind, if we're sure2Point, is it necessary to blindly enumerate the third point? The answer is in the negative. In fact, we look at the two-point line as a slope and treat him asyAxis You will find that the third point is obviously in the coordinate system to find a left"YShaftThe nearest point is to calculate the area to update the answer. Then we can continue to think about it and find that we can take the point according to a slope as "yShaft"Make" left-to-right "sorting, so that when2Point collinear, with these two points of the left and right2a point to update the answer just fine. In other words, we adopt a rotational coordinate system, and start byxcoordinates in order, think directly with the vertical slope, and then maintain the words each time in fact, when the two-point collinear as long as the exchange they can get the slope to turn over the sequence of the event point. So we can preprocess all the possible slopes, as events, and constantly rotate the coordinate system to update the answer. This complexity is onlyn^2, the desired score. (It's really just a brute force optimization. Don't hit me .t_t)
(It seems to be complicated ...) )
1#include <cstdio>2#include <ctime>3#include <cstdlib>4#include <cmath>5#include <algorithm>6 Const DoublePi=3.1415926535897932384626;7 structp{Doublex, y;} a[1010],z,b[1010];intN,k;Doubleans=1e10,tmp,t;8 BOOL operator< (PConst&a,pConst&B) {returna.x<b.x| | (a.x==b.x&&a.y<b.y);}9Poperator+ (PConst&a,pConst&B) {returnP {a.x+b.x,a.y+b.y};}TenPoperator, (1Const&a,pConst&B) {returnP {a.x-b.x,a.y-b.y};} OnePoperator* (PConst&a,DoubleP) {returnP {a.x*p,a.y*p};} APoperator* (PConst&a,pConst&B) {returnP {a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};} - DoubleCross (PConst&a,pConst&B) {returna.x*b.y-a.y*b.x;} - DoubleDot (PConst&a,pConst&B) {returna.x*b.x+a.y*b.y;} the intMain () - { -scanf"%d", &n);inti,j;k= (int) sqrt (n) +Ten;//Srand (Time (0)); - for(i=1; i<=n;i++) scanf ("%LF%LF",&a[i].x,&a[i].y); + if(n<= -) - { + for(i=1; i<n;i++) A for(j=i+1; j<n;j++) at for(k=j+1; k<=n;k++) - { -Tmp=std::abs (Cross (a[k]-a[i],a[j]-a[i])); - if(ans>tmp) ans=tmp; - } -printf"%.2lf\n", ans/2.0); in } - Else{intp1= to, p2= at; to for(inttt=1; tt<=p1;tt++) + { -Z= (P) {cos (pi/p2*tt), sin (pi/p2*tt)}; the for(i=1; i<=n;i++) b[i]=a[i]*Z; *Std::sort (b +1, B +1+n); $ for(intkk=1;(kk-1) *k<=n;kk++)Panax Notoginseng for(I= (k* (kk-1)+1); i<n&&i<k*kk;i++) - for(j=i+1; j<n&j<k*kk;j++) the for(intl=j+1; l<=n&&l<k*kk;l++) + { ATmp=std::abs (Cross (b[l]-b[i],b[j]-b[i])); the if(ans>tmp) ans=tmp; + } - } $printf"%.2lf\n", ans/2.0); $ } -}
View Code