http://codeforces.com/contest/614/problem/C

题意:给你一个N多边形,求其围绕多边形外一个顶点旋转一圈扫过的面积;



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000;
double max(double a,double b)
{return a>b?a:b;};
double min(double a,double b)
{return a<b?a:b;};


const int max_=100000;
struct Point{
double x,y;
Point(double xx,double yy):x(xx),y(yy){}
Point(){};
}p[max_+5];
Point o;
Point operator -(Point a,Point c)
{
return Point(a.x-c.x,a.y-c.y);
}

int n;


double Dot(Point a,Point b)
{
return  a.x*b.x+a.y*b.y;
}

double dist(Point a,Point b)
{
return sqrt(Dot(a-b,a-b));
}

double Cross(Point a,Point b)
{
return fabs(a.x*b.y-b.x*a.y);
}

double Pointtoline(Point o,Point a,Point b)
{
return Cross(o-a,b-a)/dist(a,b);
}

double Pointtosegment(Point o,Point a,Point b)
{
if(Dot(o-a,b-a)<0) return dist(o,a);
else if(Dot(o-b,a-b)<0) return dist(o,b);
else return Pointtoline(o,a,b);
}

int main()
{
while(~scanf("%d %lf %lf",&n,&o.x,&o.y))
{
double minn=inf,maxn=0;
for(int i=0;i<n;i++)
            scanf("%lf %lf",&p[i].x,&p[i].y);
        p[n]=p[0];

for(int i=0;i<n;i++)
{
double temp=Pointtosegment(o,p[i],p[i+1]);
             minn=min(minn,temp);
             maxn=max(maxn,dist(p[i],o));
}
        printf("%.18f\n",pi*(maxn*maxn-minn*minn));
}
return 0;
}
分析:只要求出这个点到多边形的最短距离和最远距离就好,最大距离是肯定在多边形的
点上的,最短距离则可能在边上,也可能在点上,那么只要求出点到线段的最短距离就好。