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 ...
随机推荐
- 0.2 IDEA配置
一.IDEA配置maven 在启动配置设置清理方式:clean jetty:run maven版本以及本地setting和repository JRE版本以及编码格式:-Dfile.encoding= ...
- BZOJ1123 BLO
割点的好题. 联通图,难度降低.首先对于一个点,如果他不是割点,那它的贡献是2*(n-1),就是任何一个其他节点都少了正反两个数对,这个看样例可以看出来. 如果它是一个割点,去掉他以后会出现若干个联通 ...
- java web过滤器防止未登录进入界面
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import ja ...
- SRS之信号的管理:SrsSignalManager
1. 综述 SRS 中使用了 State Threads 协程库,该库对信号的处理是将信号事件转换为 I/O 事件.主要做法是:对关注的信号设置同样地信号处理函数 sig_catcher(),该函数捕 ...
- LeetCode 21. 合并两个有序链表(Merge Two Sorted Lists)
题目描述 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1-& ...
- Java-GC 垃圾收集器(HotSpot)
垃圾收集器为垃圾收集算法的具体实现,是执行垃圾收集算法的,是守护线程. HotSpot 虚拟机采用分代收集(JVM 规范并未对堆区进行划分),将堆分为年轻代和老年代,垃圾收集器也按照这样区分.不过已有 ...
- 转: zepto的使用方法
有些不了解zepto的同学在刚接触的时候肯定有很多疑惑,这个东西怎么用啊,去哪里下载啊,什么时候该用什么时候不该用啊,其实我以前也是这样的.jquery使用多了那么就让我们一起来了解下zepto把. ...
- MySQL操作符与相关函数
union(联合)union使用是关联两张表或者两个查询所查出来的数据,联合成一张表但不会出现重复数据,显示的字段必须匹配列数. select s3.id cid,s1.cityName provin ...
- java:常见问题(解决获取properties乱码,解决poi自适应宽度)
1.解决获取properties乱码 File cf = new File("D:\\app\\java_jar\\config.properties"); String[] pa ...
- Redis客户端基本操作以及查看慢查询
1.连接 redis-cli.exe -h 127.0.0.1 -p 6379 2.验证密码 λ redis-cli.exe -h 127.0.0.1 -p 6379127.0.0.1:6379> ...