大意: 给定多边形, 给定点$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. ettercap局域网DNS切换到恶意网址

    ettercap -i eth0 -Tq -M arp:remote -P dns_spoof /// /// Dns欺骗--Ettercap工具进行Dns欺骗 转载至 https://blog.cs ...

  2. Python中很少见的用法

    print(*range(10)) # 自动解开可迭代的对象

  3. 0.JQuery安装

    jQuery 安装 网页中添加 jQuery 可以通过多种方法在网页中添加 jQuery. 您可以使用以下方法: 从 jquery.com 下载 jQuery 库 从 CDN 中载入 jQuery, ...

  4. redux异步

    在一个项目中 redux 是必不可少的,redux 中没有提供异步的操作,但是异步又是项目开发中重要的一部分,所以我们的 redux 对此有进行了拓展: 所以我们需要 redux-thunk 的插件, ...

  5. ant DatePicker 中文

    方式一:局部设置 import 'moment/locale/zh-cn'; import locale from 'antd/lib/date-picker/locale/zh_CN'; //调用时 ...

  6. oracle中关于clob类型字段的查询效率问题

    今天,公司项目某个模块的导出报如下错误: HTTP Status 500 – Internal Server Error Type Exception Report Message Handler d ...

  7. 配置Log4j 详解

    Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行环境 ...

  8. maven 打包异常

    异常信息: [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.6.RELEASE ...

  9. RN在Mac环境下开发环境搭建

    1.推荐使用Homebrew来安装 Node 和 Watchman.在命令行中执行下列命令安装: brew install node brew install watchman 如果你已经安装了 No ...

  10. 关于bootstrap按钮的偏移

    <body> <div id="divForm" class="addView"> <div class="form-h ...