Hoj 1157 Scud busters

Source: Internet
Author: User
Question: N convex packets are given. Now we need to use a bomb to blow up the fixed coordinates. The convex hull where the attacked coordinates are located will be destroyed. Now we ask you to analyze the area of the destroyed convex hull: convex hull + Polygon Area

 

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> using namespace STD; const int x = 105; # define debug puts ("here"); int top, n, a [X]; bool use [X]; struct node {int X, Y; friend bool operator <(node A, Node B) {return. Y <B. Y | (. y = B. Y &. x <B. x) ;}} res [X], p [X], in [25] [X]; int det (INT X1, int Y1, int X2, int Y2) {return X1 * y2-x2 * Y1;} bool del (INT top, int I) {If (det (RES [t OP]. x-res [Top-1]. x, Res [Top]. y-res [Top-1]. y, P [I]. x-res [Top]. x, p [I]. y-res [Top]. y) <= 0) return true; return false;} void Graham () {sort (p, p + n); Top = 1; res [0] = P [0]; Res [1] = P [1]; for (INT I = 2; I <n; I ++) {While (top & del (top, I) Top --; Res [++ top] = P [I] ;} int mint = top; res [+ TOP] = P [N-2]; for (INT I = n-3; I> = 0; I --) {While (top! = Mint & del (top, I) -- top; Res [++ top] = P [I] ;}} int det (node A, Node B, node O) {return (. x-o.x) * (B. y-o.y)-(. y-o.y) * (B. x-o.x);} bool check (node cur, int ID) {for (INT I = 0; I <A [ID]-1; I ++) if (det (in [ID] [I], in [ID] [I + 1], cur) * det (in [ID] [I + 1], in [ID] [I + 2], cur) <0) return false; return true;} double DIS (node A, Node B) {return SQRT (. x-b.x) * 1.0 * (. x-b.x) +. y-b.y) * (. y-b.y);} double CAL (int id) {double ans = 0; f Or (INT I = 1; I <A [ID]; I ++) ans + = det (in [ID] [I], in [ID] [I + 1], in [ID] [0]); ANS/= 2; ans = max (ANS,-ans); Return ans ;} double solve (int x, int y, int CNT) {node cur; cur. X = x; cur. y = y; For (INT I = 1; I <= CNT; I ++) if (! Use [I] & check (cur, I) {use [I] = true; return CAL (I) ;}return 0 ;} int main () {memset (use, false, sizeof (use); int CNT = 0; while (CIN> n, n! =-1) {for (INT I = 0; I <n; I ++) scanf ("% d", & P [I]. x, & P [I]. y); Graham (); CNT ++; For (INT I = 0; I <= top; I ++) in [CNT] [I] = res [I]; A [CNT] = top;} int X, Y; double ans = 0; while (CIN> x> Y) ans + = solve (X, Y, CNT ); printf ("%. 2lf \ n ", ANS); 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.