[Convex Hull] HDU 3285

Source: Internet
Author: User

Because the regular convex hull is saved counter-clockwise, you only need to find the point in the upper left corner, and then go back to it to OK! The original template did not judge the common points, resulting in n times of Wa !!!

# Include <iostream> # include <vector> # include <map> # include <stack> # include <algorithm> # include <queue> # include <list> # include <set> # include <string. h> # include <stdlib. h> # include <math. h> # include <stdio. h> # include <ctype. h> # include <iomanip> using namespace STD; # define ll long # define PI ACOs (-1) # define fre freopen ("a.txt", "r", stdin) # define INF 9999999999 # define EPS 1e-6 # define N 55 struct point {int X, Y;}; Poin T p [N], chull [N], P0, stck [N]; int m; // Number of convex hull vertices int N; // All Points // (B,) X (C, A) int CNT; int cross (point a, point B, point C) {return (B. x-a.x) * (C. y-a.y)-(B. y-a.y) * (C. x-a.x);} // <0 then Ac in AB clockwise, need clockwise turn int DIS (point a, point B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} // sorting bool CMP (point a, point B) {int T = cross (P0, A, B ); return T> 0 | (t = 0 & DIS (P0, A) <DIS (P0, B )); // T> 0 indicates that p0b is in p0a counterclockwise} void convexhull () {int I, J, K; M = 0; CNT = 0; For (k = 0, I = 0; I <n; I ++) if (P [I]. Y <p [K]. Y | (P [I]. y = P [K]. Y & P [I]. x <p [K]. x) k = I; p0 = P [k]; // base point P [k] = P [0]; P [0] = P0; sort (p + 1, P + N, CMP); stck [0] = P [0]; stck [1] = P [1];/* int flag = 0; if (Cross (stck [0], stck [1], p [2]) = 0) {flag = 1; stck [1] = P [2];} if (FLAG) I = 3; else I = 2; */INT Top = 1; for (I = 2; I <n; I ++) {While (top & cross (stck [Top-1], stck [Top], p [I]) <= 0) // That's it !!! <= 0 Ah {top --;} stck [++ top] = P [I];} M = Top + 1;} bool CCMP (point a, point B) {if (. y = B. y) return. x <B. x; return. y> B. y;} int main () {int t; scanf ("% d", & T); While (t --) {int CA; int I, J; scanf ("% d", & Ca, & N); for (I = 0; I <n; I ++) scanf ("% d ", & P [I]. x, & P [I]. y); convexhull (); int xx = stck [0]. x, YY = stck [0]. y; int tag = 0; for (I = 1; I <m; I ++) if (stck [I]. y> stck [tag]. Y | (stck [I]. y = stck [tag]. Y & stck [I]. x <stck [tag]. x) Tag = I; printf ("% d \ n", CA, m); for (I = tag; I> = 0; I --) printf ("% d \ n", stck [I]. x, stck [I]. y); for (I = s-1; I> tag; I --) printf ("% d \ n", stck [I]. x, stck [I]. y);} return 0 ;}
Related Keywords:

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.