Original question connection: http://poj.org/problem? Id = 1113
Give N points. You can see a wall so that the distance between all points and the wall is no less than l. Length of the wall ..
Idea: first obtain the convex hull of N points, and then build a wall based on the convex hull. One part of the wall is the convex hull length, and the other part is a circle with the radius of L !!
Code:
# Include <stdio. h> # include <string. h> # include <math. h ># include <algorithm> using namespace STD; int M, top; struct point {int X, Y;} p [2000], s [2000], T; void find_pole_point () // finds the base point and switches it to 0 {int I, j = 0; t = P [0]; for (I = 1; I <m; I ++) {If (P [I]. Y <t. Y | (P [I]. y = T. Y & P [I]. x <t. x) {J = I; t = P [I] ;}} T = P [0]; P [0] = P [J]; P [J] = T;} double DIS (point T1, point t2) // calculate the distance between two points {Double Z = (t1.x-t2.x) * (t1.x-t2.x) + (t1.y-t2.y) * (t1.y-t2.y); Return SQRT (z) ;} Double cross (point T1, point t2, point T3, point T4) // vector Cross Product {return (t2.x-t1.x) * (t4.y-t3.y) -(t2.y-t1.y) * (t4.x-t3.x);} bool CMP (point T1, point t2) {Double Z = cross (P [0], T1, P [0], T2); Return Z? Z> 0: DIS (P [0], T1)> DIS (P [0], T2);} void trim () // returns the convex hull {int I, J; find_pole_point (); sort (p + 1, P + M, CMP); s [0] = P [0]; s [1] = P [1]; top = 1; for (I = 2; I <m; I ++) {While (Cross (s [Top-1], s [Top], s [Top], P [I]) <0) Top --; top ++; s [Top] = P [I] ;}} int main () {int I, j, ncase, l; while (scanf ("% d", & M, & L )! = EOF) {for (I = 0; I <m; I ++) scanf ("% d", & P [I]. x, & P [I]. y); Round (); double ans = 2*3.1415926 * l; for (I = 0; I <= top; I ++) ans + = DIS (s [I], s [(I + 1) % (top + 1)]); printf ("%. 0lf \ n ", ANS );}}