Peter and Snow Blower

题意:有n(3 <= n <= 100 000)个点的一个多边形,这个多边形绕一个顶点转动,问扫过的面积为多少?

思路:开始就认为是一个凸包的问题,像poj2187求点对平方的最大值一样,但是有一个点是确定的(ps:这道题在div1里面可是A啊!这么复杂?),所以直接求解即可,时间复杂度也就O(n);还有就是怎么求多边形到确定点的最小距离呢?这就不只是暴力求点对之间的距离这么简单了。因为一个多边形绕一个点转动时,有时候是定点到边的距离,所以转化为了点到线段的最短距离,使用了向量点积和叉积的性质即可求解;还有注意使用int会爆了问题。。。WA了几次

#include<bits/stdc++.h>
using namespace std;
`#define inf 0x3f3f3f3f
const double PI = acos(-1.0);
struct point{
int x,y;
point(){}
point(int _x,int _y){
x = _x; y = _y;
}
long long operator *(const point &b)const{// 叉乘
return (1LL*x*b.y - 1LL*y*b.x);
}
point operator -(const point &b)const{
return point(x - b.x,y - b.y);
}
long long dot(const point &b){ //点乘
return 1LL*x*b.x + 1LL*y*b.y;
}
double dist(const point &b){
return sqrt(1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y));
}
long long dist2(const point &b){
return 1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y);
}
double len(){
return sqrt(1LL*x*x+1LL*y*y);
}
void input(){
scanf("%d%d",&x,&y);
}
}; double point_to_segment(point a,point b,point c)//点a到“线段” bc的距离
{
point v[4];
v[1] = {c.x - b.x,c.y - b.y};
v[2] = {a.x - b.x,a.y - b.y};
v[3] = {a.x - c.x,a.y - c.y};
if(v[1].dot(v[2]) < 0) return v[2].len();
if(v[1].dot(v[3]) > 0) return v[3].len();
return fabs(1.*(v[1]*v[2])/v[1].len());
}
const int MAXN = 1e5+10;
point p[MAXN];
int main()
{
int n,i;
cin>>n;
for(i = 0;i <= n;i++){
p[i].input();
}
p[++n] = p[1];
double mx = 0.0,mn = 1.*inf;
for(i = 1;i < n;i++){
mx = max(mx,p[0].dist(p[i]));
mn = min(mn,point_to_segment(p[0],p[i],p[i+1]));
}
printf("%.12f\n",PI*(mx*mx - mn*mn));
}

codeforce #339(div2)C Peter and Snow Blower的更多相关文章

  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. A. Peter and Snow Blower 解析(思維、幾何)

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

  3. [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 ...

  4. 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 ...

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

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

  6. 【CodeForces 613A】Peter and Snow Blower

    题 题意 给出原点(不是(0,0)那个原点)的坐标和一个多边形的顶点坐标,求多边形绕原点转一圈扫过的面积(每个顶点到原点距离保持不变). 分析 多边形到原点的最小距离和最大距离构成的两个圆之间的圆环就 ...

  7. codeforces 613A. Peter and Snow Blower

    题目链接 给一个多边形, 一个多边形外的定点, 求这个点距离多边形的最短距离和最长距离. 最长距离肯定是和某个顶点的连线, 而最短距离是和点的连线或是和某条边的连线. 对于一条边上的两个点a, b, ...

  8. CodeForces 614C Peter and Snow Blower

    简单计算几何,只要算出圆心到多边形上的最短距离和最长距离即可 #include<cstdio> #include<cstring> #include<cmath> ...

  9. CF613A:Peter and Snow Blower

    用一个圆心在(x,y)的圆环覆盖一个n边形,顺或逆时针给出n边形所有顶点,求圆环最小面积. 卡了好久,各种傻逼错误.. 题目就是让我们固定一大一小两个边界圆,我们来看看这两个圆满足什么条件. 首先外面 ...

随机推荐

  1. 用linq实现登陆功能

    BLL层的逻辑代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; name ...

  2. C#_MVC_ajax for form

    在上一篇介绍MVC中的Ajax实现方法的时候,曾经提到了除了使用Ajax HTML Helper方式来实现之外,Jquery也是实现Ajax的另外一种方案. 通过get方法实现AJax请求 View ...

  3. marine

  4. java基础常识

    现在总结一些经常接触到的java名词 一:java技术分类 javase:java standard editor:java标准版,主要定义java经常使用的API(Application Progr ...

  5. Python基础【第十一篇】文件操作(file()、open()方法和fileinput模块)

    一.file/open 内置函数 file函数的方法: 注:file 和 open的用法和功能相同这里只对file进行分析 file(‘filename’,’mode’) file(‘filename ...

  6. 关于JFace带复选框的树

    树的复选框用CheckboxTreeViewer实现.由于其子类ContainerCheckedTreeViewer在没有选择全部子节点时可以自动将父节点设置成灰选,所以实现树的复选框更多的是用Con ...

  7. RabbitMQ 原文译1.2--"Hello Word"

    本系列文章均来自官网原文,属于个人翻译,如有雷同,权当个人归档,忽喷. .NET/C# RabbitMQ 客户端下载地址:https://github.com/rabbitmq/rabbitmq-do ...

  8. 以 280W 数据为依据。对比SQL2008 表分区前和分区后的 T_SQL 效率

    一: 数据库的优化一直项目后期的重中之重,特别是当单表数据庞大到1000W时候.各种SQL语句执行效率都会慢很多.SQL 效率 与索引,行数据,列数据,以及Where 刷选字段类型 (效率 整数型大于 ...

  9. mysql安全

    安装MySql时,尽量选择别的端口(默认是3306),密码设复杂一点!在next的步骤中,注意不要选中"允许远程登录". Web漏洞检测及修复 http://wiki.open.q ...

  10. navagationController 的子控制器如何取消右滑返回

    1.首先在navagationController的某个控制器中 遵守:UIGestureRecognizerDelegate 2.在viewDidload中设置: self.navigationCo ...