Poj3348 Cows convex hull + Polygon Area Water question

Source: Internet
Author: User

/* Poj3348 Cows convex bag + Polygon Area Water question floor rounded down, returns double */# include <stdio. h> # include <math. h ># include <algorithm> using namespace std; const double eps = 1e-8; struct point {double x, y ;}; int n; point dian [10000 + 10], zhan [10000 + 10]; //////////////////////////////////////// /// // point * mo_dian; double mo_distance (point p1, point p2) {return sqrt (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y ));} double mo_xmult (poin T p2, point p0, point p1) // p1 returns a negative value on the left of p2, and returns a positive {return (p1.x-p0.x) * (p2.y-p0.y) on the right) -(p2.x-Snapshot x) * (p1.y-Snapshot y);} bool mo_ee (double x, double y) {double ret = x-y; if (ret <0) ret =-ret; if (ret <eps) return 1; return 0;} bool mo_gg (double x, double y) {return x> y + eps ;} // x> y bool mo_ll (double x, double y) {return x <y-eps;} // x <y bool mo_ge (double x, double y) {return x> y-eps;} // x> = y bool mo_le (double x, Double y) {return x <y + eps;} // x <= y bool mo_cmp (point a, point B) // The first order {if (mo_ee (. y, B. y) return mo_ll (. x, B. x); return mo_ll (. y, B. y);} bool mo_cmp1 (point a, point B) // second sort {double len = mo_xmult (B, mo_dian [0], a); if (mo_ee (len, 0.0) return mo_ll (mo_distance (mo_dian [0], a), mo_distance (mo_dian [0], B); return mo_gg (len, 0.0 );} int mo_graham (int n, point * dian, point * stk) {int I, t Op = 1; mo_dian = dian; sort (mo_dian, mo_dian + n, mo_cmp); sort (mo_dian + 1, mo_dian + n, mo_cmp1 ); stk [0] = mo_dian [0]; stk [1] = mo_dian [1]; for (I = 2; I <n; ++ I) {while (top> 0 & mo_xmult (mo_dian [I], stk [top-1], stk [top]) <= 0) -- top; stk [++ top] = mo_dian [I];} return top + 1;} double mo_area_polygon (point * dian, int n) {int I; point yuan; yuan. x = yuan. y = 0; double ret = 0; for (I = 0; I <n; ++ I) {ret + = mo_xmult (dian [(I + 1) % n], yuan, dian [I]);} if (re T <0) ret =-ret; return ret/2;} // int main () {int I; while (scanf ("% d ", & n )! = EOF) {for (I = 0; I <n; ++ I) {scanf ("% lf", & dian [I]. x, & dian [I]. y);} int ret = mo_graham (n, dian, zhan); double area = mo_area_polygon (zhan, ret); printf ("%. 0lf \ n ", floor (area/50);} 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.