POJ 1228 (stable convex hull)

Source: Internet
Author: User

Language: Grandpa's EstateTime Limit: 1000 MS Memory Limit: 10000 KTotal Submissions: 8990 Accepted: 2383 DescriptionKamran the Believer inherits a grandmother's convex polygon estate. the perimeter of the manor is surrounded by ropes and wooden piles. but some ropes and stakes are missing. check whether the manor surrounded by remaining wooden piles is a stable convex bag (that is, the remaining nail can determine a unique convex bag ). the number of data groups in the first row of Input www.2cto.com is t (1 <= t <= 10 ). for each group of data, the first behavior n (1 <= n <= 1000) indicates the number of wooden piles. in the next n rows, the coordinates (x, y) of each behavior are fixed to an integer. output outputs YES or NO for each group of data, indicating whether the data is stable. sample Input16 0 01 23 42 02 4 5 0 Sample Outpu TNOSourceTehran 2002 Preliminary to ensure stability of a convex hull, if and only if any side of the convex hull has more than three wooden piles (including endpoints) proof: After the convex hull is created, enumerate, click 3rd on the edge. [Cpp] # include <cstdio> # include <cstring> # include <cstdlib> # include <cmath> # include <cctype> # include <iostream> # include <functional> # include <algorithm> using namespace std; # define MAXT (10 + 10) # define MAXN (1000 + 10) // # define sqr (x) (x * x) int sqr (int x) {return x * x;} struct P {int x, y; P () {} P (int _ x, int _ y): x (_ x ), y (_ y) {} friend istream & operator> (istream & cin, P & a) {cin>. x>. y; return cin;} Friend double dis (P a, P B) {return sqrt (double (sqr (. x-b.x) + sqr (. y-b.y);} a [MAXN]; struct V {int x, y; V () {} V (int _ x, int _ y ): x (_ x), y (_ y) {} V (P a, P B): x (B. x-a.x), y. y-a.y) {} friend int operator * (V a, V B) {return. x * B. y-a.y * B. x ;}}; int cmp (p a, p B) {int temp = V (a [1], A) * V (a [1], B ); if (temp> 0) return 1; else if (temp = 0 & dis (a [1], A) <dis (a [1], B )) return 1; else return 0;} int t, n, st [MAXN ]; Bool solve () {int size = 1; st [0] = 1; st [1] = 1; int j = 2; while (j <= n) {if (size <2 | V (a [st [size-1], a [st [size]) * V (a [st [size], a [j])> 0) {st [++ size] = j ++;} else size --;} a [++ n] = a [1]; st [+ size] = n; for (int I = 1; I <size; I ++) {/* int k = st [I-1] + 1; (; k <st [I + 1]; k ++) if (k! = St [I] & V (a [st [I], a [st [I + 1]) * V (a [st [I], a [st [k]) = 0) break; if (k = st [I + 1]) return 0; */int k = 1; (; k <n; k ++) if (k! = St [I] & k! = St [I + 1] & V (a [st [I], a [st [I + 1]) * V (a [st [I], a [k]) = 0) break; if (k = n) return 0;} return size> = 4;} int main () {// freopen ("poj1228.in", "r", stdin); cin> t; while (t --) {cin> n; for (int I = 1; I <= n; I ++) cin> a [I]; if (n <6) {cout <"NO \ n"; continue ;} int p = 1; for (int I = 2; I <= n; I ++) if (a [I]. x <a [p]. x | (a [I]. x = a [p]. x) & (a [I]. y <a [p]. y) p = I; swap (a [1], a [p]); sort (a + 2, a + 1 + n, cmp ); // cout <dis (P (), P () <dis (P (), P (); if (solve ()) cout <"YES \ n"; else cout <"NO \ n";} return 0;} remarks: If you replace sqr with define, "nan" is output"

Related Article

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.