大意: 给定多边形, 给定点$P$, 求一个以$P$为圆心的最小的圆环包含整个多边形.

#include <iostream>
#include <cmath>
#define REP(i,a,b) for(int i=a;i<=b;i++) const double eps=1e-8; int dcmp(double x) {return fabs(x)<=eps?0:x>eps?1:-1;} const int N = 1e5+10;
struct Point {
double x,y;
Point(double x=0,double y=0):x(x),y(y) {}
Point operator + (const Point &a) {return Point(x+a.x,y+a.y);}
Point operator - (const Point &a) {return Point(a.x-x,a.y-y);}
Point operator * (double a) {return Point(x*a,y*a);}
Point operator / (double a) {return Point(x/a,y/a);}
bool operator < (const Point &b) const {return x<b.x||(x==b.x&&y<b.y);}
bool operator == (Point b) {return dcmp(x-b.x)==0&&dcmp(y-b.y)==0;}
double length() {return sqrt(x*x+y*y);}
Point rotate(double rad) {return Point(x*cos(rad)-y*sin(rad),x*sin(rad)+y*cos(rad));}
Point normal(Point a) {return Point(-a.y/a.length(),a.x/a.length());}
} a[N]; typedef Point Vector; double Cross(const Vector& a,const Vector& b) {return a.x*b.y-b.x*a.y;}
double Dot(Vector a,Vector b) {return a.x*b.x+a.y*b.y;}
double Angle(Vector a,Vector b) {return acos(Dot(a,b)/a.length()/b.length());}
double Area(Point a,Point b,Point c) {return Cross(b-a,c-a);} bool OnSegment(Point p,Point a,Point b) {return dcmp(Cross(a-p,b-p))==0&&dcmp(Dot(a-p,b-p))<0;}
bool Segment_Intersection(Point a1,Point a2,Point b1,Point b2) {return dcmp(Cross(a2-a1,b1-a1))*dcmp(Cross(a2-a1,b2-a1))<0&&dcmp(Cross(b2-b1,a1-b1))*dcmp(Cross(b2-b1,a2-b1))<0;}
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w) {return P+v*(Cross(P-Q,w)/Cross(v,w));}
double DistanceToLine(Point p,Point a,Point b) {Vector v1=b-a,v2=p-a;return fabs(Cross(v1,v2))/v1.length();}
double DistanceToSegment(Point p,Point a,Point b) {
if(a==b)return (p-a).length();
Vector v1=b-a,v2=p-a,v3=p-b;
if(dcmp(Dot(v1,v2))<0)return v2.length();
else if(dcmp(Dot(v1,v3))>0)return v3.length();
else return DistanceToLine(p,a,b);
} double Area(int n,Point* P) {
double ans=0;
for(int i=2; i<n; i++)ans+=Area(P[1],P[i],P[i+1]);
return ans/2;
} int main() {
int n,x,y;
scanf("%d%d%d", &n, &x, &y);
double mi = 1e18, ma = -1e18;
REP(i,1,n) {
int xx, yy;
scanf("%d%d", &xx, &yy);
a[i]=Point(xx-x,yy-y);
ma=max(ma,a[i].length());
}
REP(i,2,n) mi=fmin(mi,DistanceToSegment(Point(),a[i],a[i-1]));
mi=fmin(mi,DistanceToSegment(Point(),a[n],a[1]));
printf("%.12lf\n",acos(-1)*(ma*ma-mi*mi));
}

Peter and Snow Blower CodeForces - 613A (点到线段距离)的更多相关文章

  1. Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何

    A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...

  2. [CodeForces - 614C] C - Peter and Snow Blower

    C - Peter and Snow Blower Peter got a new snow blower as a New Year present. Of course, Peter decide ...

  3. codeforce #339(div2)C Peter and Snow Blower

    Peter and Snow Blower 题意:有n(3 <= n <= 100 000)个点的一个多边形,这个多边形绕一个顶点转动,问扫过的面积为多少? 思路:开始就认为是一个凸包的问 ...

  4. A. Peter and Snow Blower 解析(思維、幾何)

    Codeforce 613 A. Peter and Snow Blower 解析(思維.幾何) 今天我們來看看CF613A 題目連結 題目 給你一個點\(P\)和\(n\)個點形成的多邊形(照順或逆 ...

  5. NEU 1496 Planar map 计算几何,点到线段距离 难度:0

    问题 H: Planar map 时间限制: 1 Sec  内存限制: 128 MB提交: 24  解决: 22[提交][状态][讨论版] 题目描述 Tigher has work for a lon ...

  6. POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内

    首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...

  7. Codeforces Round #339 Div.2 C - Peter and Snow Blower

    Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. A ...

  8. 【14.36%】【codeforces 614C】Peter and Snow Blower

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)

    A Round Peg in a Ground Hole Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4438   Acc ...

随机推荐

  1. python中的定时器threading.Timer

    由浅入深学SQL Server 2012 --> python开发中用到,定时操作.例如每隔1s执行一次,发现  threading.Timer,这个东西,可以直接用. 其原理为执行函数中置定时 ...

  2. TCP输出 之 tcp_transmit_skb

    概述 tcp_transmit_skb的作用是复制或者拷贝skb,构造skb中的tcp首部,并将调用网络层的发送函数发送skb:在发送前,首先需要克隆或者复制skb,因为在成功发送到网络设备之后,sk ...

  3. PHP压缩图片并模糊处理(抄的哟)

    class image_blur{ /** * 图片高斯模糊(适用于png/jpg/gif格式) * @param $srcImg 原图片 * @param $savepath 保存路径 * @par ...

  4. Python 之 subprocess模块

    一.subprocess以及常用的封装函数运行python的时候,我们都是在创建并运行一个进程.像Linux进程那样,一个进程可以fork一个子进程,并让这个子进程exec另外一个程序.在Python ...

  5. Java Jsch SFTP 递归下载文件夹

    Java Program For Downloading Folder Content recursively from SFTP Server How to download folder from ...

  6. node-sass 安装失败 win32-x64-57_binding.node

    安装npm install环境的时候我遇到一个问题就是  缺少node-sass文件 用这行命令: node -p "[process.platform, process.arch, pro ...

  7. Spring AOP增强(Advice)

    Sring AOP通过PointCut来指定在那些类的那些方法上织入横切逻辑,通过Advice来指定在切点上具体做什么事情.如方法前做什么,方法后做什么,抛出异常做什么. Spring中有两种方式定义 ...

  8. C++中的各种容器实现原理

    C++ 容器及选用总结 vector 拥有一段连续的内存空间 list 就是数据结构中的双向链表 deque 的动态数组首尾都开放 set 有序的容器,红黑树的平衡二叉检索树的数据结构 multise ...

  9. vue路由跳转到登录页

    // 第一种 { path:'/', component: require('../components/Login.vue') }, // 第二种 { path: '/', redirect: '/ ...

  10. python 学习笔记(二):为元组的每个元素命名,提高程序的可读性

    在程序中有些数据为固定格式时,即字段数量确定.字段位置顺序确定不变,我们就可以用元组来储存.使用元组的优势是储存空间很小,访问速度也很快.如下代码对每个学生信息用元组来表示: # ('Jim', 16 ...