POJ 1113 Wall

Source: Internet
Author: User

The test instructions of this is that the distance between all points on the circle and the original point is greater than or equal to L. To find the shortest perimeter.

Translate it, geometric mess? found that the arc was just a circle.

Convexhull. This I copy of the version also do not know what algorithm but it seems to be reliable. An algorithm for the study of convex hull.

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace Std;
struct POINT
{
int x, y;
Point (int x=0,int y=0): X (x), Y (y) {}
};
typedef point Vector;
Point ch[1010],p[1010];
Const Double Pi=atan (1.0);
int n;
int cross (vector a,vector B)
{
return a.x*b.y-a.y*b.x;
}
Vector operator + (vector a,vector b)
{
return vector (A.X+B.X,A.Y+B.Y);
}
Vector operator-(vector a,vector B)
{
return vector (A.X-B.X,A.Y-B.Y);
}
Vector operator * (vector a,double p)
{
return vector (a.x*p,a.y*p);
}
Vector operator/(vector a,double p)
{
return vector (a.x/p,a.y/p);
}
BOOL Operator < (point A,point B)
{
return a.x<b.x| | (a.x==b.x && a.y<b.y);
}
Double Dis (point a,point B)
{
return sqrt (1.0* (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));
}
int Convexhull ()
{
Sort (p,p+n);
int m=0,k;
for (int i=0;i<n;i++)
{
while (M>1 && Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0)
m--;
Ch[m++]=p[i];
}
K=m;
for (int i=n-2;i>=0;i--)
{
while (M>k && Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0)
m--;
Ch[m++]=p[i];
}
if (n>1) m--;
return m;
}
int main ()
{
int l;
while (scanf ("%d%d", &n,&l) ==2)
{
for (int i=0;i<n;i++)
scanf ("%d%d", &p[i].x,&p[i].y);
int M=convexhull ();
Double ans=0;
for (int i=1;i<m;i++)
Ans=ans+dis (Ch[i-1],ch[i]);
Ans=ans+dis (Ch[0],ch[m-1]);
Ans=ans+2.0*pi*l;
printf ("%d\n", int (ans+0.5));
}
return 0;
}

POJ 1113 Wall

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.