Poj 1113 wall convex hull Application

Source: Internet
Author: User

Link: poj 1113 monotonic link convex bag Summary

Question: we still use a convex bag to find the shortest perimeter. We only need to add the length of a circle. We can apply the template to solve this problem;

AC code:

1 # include <iostream> 2 # include <algorithm> 3 # include <cstdio> 4 # include <cmath> 5 using namespace STD; 6 int M, N; 7 struct p 8 {9 Double X, Y; 10 friend int operator <(p a, p B) 11 {12 if (. x <B. X | (. X = B. X &. Y <B. y) 13 return 1; 14 return 0; 15} 16} A [1010], ANS [1010]; 17 double judge (p a, p B, P C) 18 {19 Return (B. x-a.x) * (C. y-a.y)-(C. x-a.x) * (B. y-a.y); 20} 21 int getnumber () // find the key point to find the shortest perimeter 22 {23 int K = 0; 24 for (INT I = 0; I <m; I ++) 25 {26 while (k> 1 & judge (ANS [K-2], ANS [k-1], a [I]) <= 0) 27 {28 K --; 29} 30 ans [k ++] = A [I]; 31} 32 int k1 = K; 33 for (INT I = s-1; i> = 0; I --) 34 {35 while (k> K1 & judge (ANS [K-2], ANS [k-1], a [I]) <= 0) 36 {37 k --; 38} 39 ans [K + +] = A [I]; 40} 41 return K-1; // The first vertex is saved twice; 42} 43 44 int main () 45 {46 scanf ("% d", & M, & N); 47 for (INT I = 0; I <m; I ++) 48 scanf ("% lf", & A [I]. x, & A [I]. y); 49 sort (A, A + M); 50 int Top = getnumber (); 51 double ans1 = 0; 52 int I; 53 for (I = 0; I <top; I ++) {54 ans1 + = SQRT (ANS [I]. x-ans [I + 1]. x) * (ANS [I]. x-ans [I + 1]. x) + (ANS [I]. y-ans [I + 1]. y) * (ANS [I]. y-ans [I + 1]. y); 55} 56 // In fact, you only need to add a circle perimeter to the end, and the outer angle of the polygon is 360 degrees; 57 ans1 + = 2*3.141592653 * N; 58 printf ("%. 0f \ n ", ans1); // G ++ (. 0l %), c ++ can return 0; 60}


 

 

Poj 1113 wall convex hull Application

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.