Peter and Snow Blower CodeForces - 613A (点到线段距离)
大意: 给定多边形, 给定点$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 (点到线段距离)的更多相关文章
- 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 ...
- [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 ...
- codeforce #339(div2)C Peter and Snow Blower
Peter and Snow Blower 题意:有n(3 <= n <= 100 000)个点的一个多边形,这个多边形绕一个顶点转动,问扫过的面积为多少? 思路:开始就认为是一个凸包的问 ...
- A. Peter and Snow Blower 解析(思維、幾何)
Codeforce 613 A. Peter and Snow Blower 解析(思維.幾何) 今天我們來看看CF613A 題目連結 題目 給你一個點\(P\)和\(n\)個點形成的多邊形(照順或逆 ...
- NEU 1496 Planar map 计算几何,点到线段距离 难度:0
问题 H: Planar map 时间限制: 1 Sec 内存限制: 128 MB提交: 24 解决: 22[提交][状态][讨论版] 题目描述 Tigher has work for a lon ...
- POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内
首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...
- 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 ...
- 【14.36%】【codeforces 614C】Peter and Snow Blower
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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 ...
随机推荐
- django CBV模式源码执行过程
在说CBV模式之前,先看下FBV的url配置方式: urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^xxx/', login), ur ...
- Linux停止被占用的端口
查找被占用的端口:netstat -lnp|grep 80 查看80端口被那些服务占用. kill掉该进程 kill -9 5574 然后在去查看一下80被占用的情况netstat -lnp|grep ...
- 伪分布式下Hadoop3.2版本打不开localhost:50070,可以打开localhost:8088
一.问题描述 伪分布式下Hadoop3.2版本打不开localhost:50070,可以打开localhost:8088 二.解决办法 Hadoop3.2版本namenode的默认端口配置已经更改为9 ...
- OUC_Summer Training_ DIV2_#4之数据结构
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26100#problem/A A - A Time Limit:1000MS Me ...
- vue-cli脚手架构建了项目,想去除Eslint验证,如何设置?
vue-cli脚手架构建了项目,想去除Eslint验证,如何设置? 在webpack.base.conf.js里面删掉下面: preLoaders: [ { test: /\.vue$/, loade ...
- tp5 多条件查询
$where['rc_category_id'] = array('eq',$cid); $where['rc_territory_ids'] = ['like', '%'.$tid.'%']; $l ...
- vmware安装centos虚拟机,没有ip地址
如果centos没有ip地址,就不能通过xshell等工具进行连接,且在上面部署的项目,外部也不能正常访问 两种方式可以解决 第一种,在安装的时候,在INSTALLATION SUMMARY界面的SY ...
- 取得远端相应Json并转化为Java对象一
JDK:1.8.0_212 IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE) 工程下载:https://files.cnblogs.com/file ...
- LC 648. Replace Words
In English, we have a concept called root, which can be followed by some other words to form another ...
- Oracle 必要的后台进程
Oracle 必要的后台进程 Table of Contents 1. 简述 2. 必要进程 2.1. 默认启动后台进程 2.2. 哪些进程不能杀 1 简述 oralce 每次大的版本变更,后台进程都 ...