Grandpa's estate --- poj1228 (convex hull)

Source: Internet
Author: User

Http://poj.org/problem? Id = 1228

Students say this is a stable convex bag. I think it is a convex bag.

The so-called stability is to determine whether the original convex hull can be added to get a larger convex hull, and this convex hull contains all the points on the original convex hull. Knowing this is simple. After finding the convex hull, you can determine whether the points on each edge are more than three points. ------ Don't worry.

The question cannot be understood. It means that each side of the convex hull has at least three points.

In addition, if there is only one line, no is output.

# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <math. h> # include <algorithm> # include <iostream> # include <queue> using namespace STD; # define n 1005 # define PI ACOs (-1.0) # define ESP 1e-8int s [N]; struct point {Double X, Y; point (double x = 0, Double Y = 0): x (x), y (y) {} point operator-(const point & temp) const {return point (x-temp.x, y-temp.y);} point operator + (const point & temp) const {return point (x + temp. x, Y + temp. y);} bool operator = (const point & temp) const {return (x = temp. X & Y = temp. y);} double operator * (const point & temp) const {return (x * temp. X + Y * temp. y);} int operator ^ (const point & temp) const {double T = x * temp. y-y * temp. x; If (T> ESP) return 1; if (FABS (t) <ESP) return 0; Return-1 ;}} P [N]; double dist (point, point B) {return SQRT (a-B) * (a-B);} int CMP (Point A1, point A2) {int t = (a1-p [0]) ^ (a2-p [0]); If (t = 0) return dist (A1, P [0]) <dist (A2, P [0]); else return T> 0 ;}int top; void Graham (int n) // returns the convex hull {s [0] = 0; s [1] = 1; Top = 1; for (INT I = 2; I <n; I ++) {While (top> 0 & (P [I]-P [s [Top]) ^ (P [s [Top-1]-P [s [Top]) <= 0) Top --; s [++ top] = I ;}} int main () {int t, n; scanf ("% d", & T); While (t --) {int K = 0; scanf ("% d ", & N); For (INT I = 0; I <n; I ++) {scanf ("% lf", & P [I]. x, & P [I]. y); If (P [I]. Y <p [K]. Y | (P [I]. y = P [K]. Y & P [I]. x <p [K]. x) k = I;} swap (P [0], p [k]); sort (p + 1, P + N, CMP); Graham (N ); s [++ top] = s [0]; int flag = 0; For (INT I = 1; I <= top; I ++) {int ans = 0; for (Int J = 0; j <n; j ++) {If (P [J]-P [s [I]) ^ (P [s [I-1]-P [s [I]) = 0) ans ++;} If (ANS <3) {flag = 1; break ;}} if (flag ==0 & top> = 3) printf ("Yes \ n"); else printf ("NO \ n ");} return 0 ;}

 

Grandpa's estate --- poj1228 (convex hull)

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.