Nyoj 78 ring pool (Entry level convex hull)

Source: Internet
Author: User

Link: nyoj 78

Question: This question is mainly about the usage of convex hull. It is an entry level. Of course, the premise is that you have been in touch with the plane ry:

AC code:

1 # include <iostream> 2 # include <algorithm> 3 # include <cstdio> 4 # include <cstring> 5 # include <vector> 6 using namespace STD; 7 struct T 8 {9 int X, Y; 10 friend int operator <(t a, t B) 11 {12 if (. x <B. x) | (. X = B. X &. Y <B. y) 13 return 1; 14 return 0; 15} 16} A [105], ANS [105]; 17 // used to judge whether the Left or Right side of the line formed by the third point is the current two points, and the return value on the right is less than 0; 18 double judge (t a, t B, t C) 19 {20 return (B. x-a.x) * (C. y-a.y)-(C. x-a.x) * (B. y-a.y); 21} 22 int main () 23 {24 int T, M; 25 scanf ("% d", & T); 26 while (t --) 27 {28 29 scanf ("% d", & M); 30 for (INT I = 0; I <m; I ++) 31 {32 scanf ("% d", & A [I]. x, & A [I]. y); 33} 34 sort (A, A + M); 35 int k1 = 0; 36 for (INT I = 0; I <m; I ++) // lower convex hull, scanning points from below; 37 {38 While (K1> 1 & judge (ANS [k1-2], ANS [k1-1], a [I]) <= 0) 39 {40 K1 --; 41} 42 ans [K1 ++] = A [I]; 43} 44 int k2 = k1; 45 for (INT I = s-1; I> = 0; I --) // top convex hull, scanning points from above; 46 {47 While (K1> k2 & judge (ANS [k1-2], ANS [k1-1], a [I]) <= 0) 48 {49 K1 --; 50} 51 ans [K1 ++] = A [I]; 52} 53 K1 --; 54 sort (ANS, ANS + k1); 55 for (INT I = 0; I <K1; I ++) 56 printf ("% d \ n", ANS [I]. x, ANS [I]. y); 57} 58 return 0; 59}

 

Nyoj 78 ring pool (Entry level 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.