Ultraviolet A 10065-Useless Tile Packers

Source: Internet
Author: User

Question: You need to add a polygon block to the ground plate of the smallest Convex Polygon and ask the percentage of the remaining space in the area of the convex polygon. Analysis: Computation of geometric and convex hull. Find the convex hull, and then divide the area difference between the polygon and convex hull by the area of the convex hull. Note: Positive and Negative vertices must be in the direction, and the vector area must be de-absolute values. [Cpp] # include <algorithm> # include <iostream> # include <cstdlib> # include <cstdio> # include <cmath> using namespace std; // point structure typedef struct pnode {int x, y, d;} point; point P [106]; // use the AB * ac int crossproduct (point a, point B, point c) {return (B. x-a.x) * (c. y-a.y)-(c. x-a.x) * (B. y-a.y);} // point-to-point distance int dist (point a, point B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} // coordinate sorting bool cmp1 (p Oint a, point B) {return (a. x = B. x )? (. Y <B. y) :(. x <B. x);} // rank bool cmp2 (point a, point B) {double cp = crossproduct (P [0], a, B); if (! Cp) return. d <B. d; else return cp> 0 ;}// calculate the convex hull double Graham (int n) {double S1 = 0.0; for (int I = 1; I <n-1; ++ I) s1 ++ = 0.5 * crossproduct (P [0], P [I], P [I + 1]); sort (P + 0, P + n, cmp1 ); for (int I = 1; I <n; ++ I) P [I]. d = dist (P [0], P [I]); sort (P + 1, P + n, cmp2); int top = 1; for (int I = 2; I <n; ++ I) {while (top> 0 & crossproduct (P [top-1], P [top], P [I]) <= 0) -- top; P [++ top] = P [I];} double S2 = 0.0; for (int I = 1; I <top; ++ I) s2 + = 0.5 * crossproduct (P [0], P [I], P [I + 1]); return 100.0 * (fabs (S2)-fabs (S1 )) /fabs (S2);} int main () {int n, t = 1; while (scanf ("% d", & n) {for (int I = 0; I <n; ++ I) scanf ("% d", & P [I]. x, & P [I]. y); printf ("Tile # % d \ n", t ++); printf ("Wasted Space = %. 2lf % \ n ", Graham (n);} 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.