POJ1228 (stability convex packet problem)

Source: Internet
Author: User

 

Question: enter a vertex on a convex bag (the vertex inside the convex bag is not, either a convex bag vertex or a dot on the convex bag side) to check whether the convex bag is stable. Stability

It is determined whether the convex hull can be added to the original convex hull to obtain a larger convex hull. The convex hull contains all vertices on the original convex hull.

 

Analysis: it is easy to know that when a convex packet is stable, each side of the convex packet must have at least three points. If there are only two points, you can add one point to get a larger convex.

Package. In this way, we can find the convex hull and add the collocated points to the convex hull. In this way, we can determine whether three consecutive three-point colons exist. For details, see the code.

 

# Include <iostream> # include <algorithm> # include <stdio. h> # include <math. h> using namespace std; const int N = 40005; typedef double DIY; struct Point {DIY x, y ;}; Point p [N]; Point stack [N]; point MinA; int top; DIY dist (Point A, Point B) {return sqrt (. x-B.x) * (. x-B.x) +. y-B.y) * (. y-B.y);} DIY cross (Point A, Point B, Point C) {return (B. x-A.x) * (C. y-A.y)-(B. y-A.y) * (C. x-A.x);} bool cmp (Point a, Point B) {DIY k = c Ross (MinA, a, B); if (k> 0) return 1; if (k <0) return 0; return dist (MinA, a) <dist (MinA, b); // The collocated points are sorted by distance from small to large} void Graham (int n) {int I; for (I = 1; I <n; I ++) if (p [I]. y <p [0]. y | (p [I]. y = p [0]. y & p [I]. x <p [0]. x) swap (p [I], p [0]); MinA = p [0]; sort (p + 1, p + n, cmp ); stack [0] = p [0]; stack [1] = p [1]; top = 1; for (I = 2; I <n; I ++) {// Note: here we also press the collocated points into the convex hull while (cross (stack [top-1], stack [top], p [I]) <0 & top> = 1) -- top; stack [++ top] = p [I] ;}} bool Judge () {for (int I = 1; I <top; I ++) {// determine whether a side of a convex hull has at least 3 points if (cross (stack [I-1], stack [I + 1], stack [I])! = 0 & (cross (stack [I], stack [I + 2], stack [I + 1])! = 0) return false;} return true;} int main () {int t, n, I; scanf ("% d", & t); while (t --) {scanf ("% d", & n); for (I = 0; I <n; I ++) scanf ("% lf ", & p [I]. x, & p [I]. y); if (n <6) {puts ("NO"); continue;} Graham (n); cout <endl; for (I = 0; I <n; I ++) cout <p [I]. x <"" <p [I]. y <endl; cout <endl; for (I = 0; I <= top; I ++) cout <stack [I]. x <"" <stack [I]. y <endl; if (Judge () puts ("YES"); else puts ("NO");} 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.