Enclosure (slope sorting + coordinate system rotation)

Source: Internet
Author: User

Problem 2 enclosure (land. cpp/c/pas) [Title Description] There are n wooden piles on the 2-dimension flat surface. You have a chance to circle the ground and get the land. In order to reflect your beautiful scenery, you need to minimize the area of your land. To enclose a polygon with at least three points, the vertex of the polygon is a wooden pile, and the land circled is the land inside the polygon. [Input format] an integer n in the first line, indicating the number of wooden piles. In the next n rows, two integers in each line represent the coordinates of a wooden pile. The coordinates are different from each other. Output Format: only one line indicates the land area with the smallest ring, with two decimal places reserved. [Sample input] example: 11 0 example: 10 21 1 [sample output] example. 50 examples. 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. Obviously, the polygon of this question must be a triangle. First, all the edges are obtained, sorted by k (which must be obtained first, but cannot be obtained directly during sorting). Then, considering these edges, we will find that they are exactly rotated around the coordinate system. That is to say, if you sort the order from left to right based on the Y axis here, you only need to change the positions of the two vertices of the edge for each side to be transferred, however, long [cpp] # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # include <functional> # include <iostream> # include <cmath> using namespace std; # define MAXN (1000 + 10) # define INF (1000000000) # define eps 1e-10 struct P {int x, y; long operator * (const P & B) {return (long) x * B. y-(long) B. x * y;} friend bool operator <(P a, P B) {if (. x ^ B. x) return. x <B. x; return. y <B. y ;}} a [MAXN]; long abs2 (long x) {if (x> 0) return x; return-x ;}int n, h [MAXN]; struct E {int I, j; double k; E () {} E (int _ I, int _ j): I (_ I), j (_ j) {if (a [I]. x = a [j]. x) k = 1e10; else k = (double) (a [I]. y-a [j]. y)/(a [I]. x-a [j]. x);} friend bool operator <(E a, E B) {return. k <B. k ;}} e [MAXN * MAXN/2]; long S2 (p a, p B, P C) {return abs2 (A * B + B * C + C * A);} int size = 0; int main () {freopen ("land. in "," r ", stdin); freopen (" land. out "," w ", stdout); scanf (" % d ", & n); for (int I = 1; I <= n; I ++) scanf ("% d", & a [I]. x, & a [I]. y); long ans = (long) 1 <60;/* for (int I = 1; I <= n-2; I ++) for (int j = I + 1; j <n; j ++) for (int k = j + 1; k <= n; k ++) ans = min (ans, abs2 (a [I] * a [j] + a [j] * a [k] + a [k] * a [I]); */sort (a + 1, a + 1 + n); for (int I = 1; I <= n; I ++) h [I] = I; for (int I = 1; I <n; I ++) for (int j = I + 1; j <= n; j ++) {e [++ size] = E (I, j);} sort (e + 1, e + 1 + size); for (int I = 1; I <= size & amp; ans; I ++) {if (h [e [I]. i]> 1 & h [e [I]. i] <n) ans = min (ans, S2 (a [h [e [I]. i]-1], a [h [e [I]. i], a [h [e [I]. i] + 1]); if (h [e [I]. j]> 1 & h [e [I]. j] <n) ans = min (ans, S2 (a [h [e [I]. j]-1], a [h [e [I]. j], a [h [e [I]. j] + 1]); swap (a [h [e [I]. i], a [h [e [I]. j]); swap (h [e [I]. i], h [e [I]. j]);} printf ("%. 2lf ", (double) ans/2); return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.