Poj 1113 wall-convex hull

Source: Internet
Author: User
/* The question is not read either. It generally means that a number of points are given, so that a wall is built, including all points, and the distance from all points is not less than l. So the main difference is to find the convex hull. Here are some explanations about the kernel <stdio. h> # include <stdlib. h> # include <math. h> struct point {int X, Y, N;} Dian [1010], STK [1010]; int N; int DIS (point a, point B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} // The returned distance is the square int cross (point P, point S, point E) {return (E. x-s.x) * (p. y-S. Y)-(P. x-s.x) * (E. y-s.y);} int CMP1 (const void * a, const void * B) // sort points in ascending order of values from Y to X, find the {point * c = (point *) A, * D = (point *) B in the lower left corner. If (c-> Y = D-> Y) return C-> X-D-> X; return C-> Y-D-> Y;} int cmp2 (const void * a, const void * B) // sort {int ret; point * c = (point *) A, * D = (point *) B; ret = cross (* D, DIAN [0], * C); If (Ret! = 0) Return-ret; else if (DIS (* C, Dian [0])> DIS (* D, Dian [0]) return 1; else return 0 ;} int tubao (point Dian [], point STK [], int N) // number of input points output by the Input Point (subscript starts from 0) returns the number of vertices on the convex hull {int I, Top = 1; qsort (Dian, N, sizeof (Dian [0]), CMP1); qsort (Dian + 1, n-1, sizeof (Dian [1]), cmp2); STK [0] = Dian [0]; STK [1] = Dian [1]; // STK [2] = Dian [2]; for (I = 2; I <n; ++ I) {While (top> 0 & cross (Dian [I], STK [Top-1], STK [Top]) <= 0) -- top; STK [++ top] = Dian [I];} return top + 1;} I NT main () {int L, I; double ret, A; while (scanf ("% d", & N, & L )! = EOF) {for (I = 0; I <n; I ++) scanf ("% d", & Dian [I]. x, & Dian [I]. y); n = tubao (Dian, STK, n); ret = 3.1415926 * l * 2; for (I = 0; I <n; I ++) {L = DIS (STK [I], STK [(I + 1) % N]); A = SQRT (double) L); RET + = ;} printf ("%. 0f \ n ", RET);} 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.