codeforce #339(div2)C Peter and Snow Blower
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的更多相关文章
- 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 ...
- A. Peter and Snow Blower 解析(思維、幾何)
Codeforce 613 A. Peter and Snow Blower 解析(思維.幾何) 今天我們來看看CF613A 題目連結 題目 給你一個點\(P\)和\(n\)個點形成的多邊形(照順或逆 ...
- [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 ...
- 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 ...
- 【CodeForces 613A】Peter and Snow Blower
题 题意 给出原点(不是(0,0)那个原点)的坐标和一个多边形的顶点坐标,求多边形绕原点转一圈扫过的面积(每个顶点到原点距离保持不变). 分析 多边形到原点的最小距离和最大距离构成的两个圆之间的圆环就 ...
- codeforces 613A. Peter and Snow Blower
题目链接 给一个多边形, 一个多边形外的定点, 求这个点距离多边形的最短距离和最长距离. 最长距离肯定是和某个顶点的连线, 而最短距离是和点的连线或是和某条边的连线. 对于一条边上的两个点a, b, ...
- CodeForces 614C Peter and Snow Blower
简单计算几何,只要算出圆心到多边形上的最短距离和最长距离即可 #include<cstdio> #include<cstring> #include<cmath> ...
- CF613A:Peter and Snow Blower
用一个圆心在(x,y)的圆环覆盖一个n边形,顺或逆时针给出n边形所有顶点,求圆环最小面积. 卡了好久,各种傻逼错误.. 题目就是让我们固定一大一小两个边界圆,我们来看看这两个圆满足什么条件. 首先外面 ...
随机推荐
- jqgrid 的编辑信息提示
在编辑时,无外乎两种结果:成功和失败.在form edit的弹出编辑窗体中隐藏了两个单元(td),一个的ID是FormError,另一个没有id,有class叫做topinfo.就是这两个家伙可以分别 ...
- 你真的会用UIButton吗? UIButton详细介绍
本节知识点: 什么是UIButton UIButton的状态 UIButton的属性设置 UIButton基本使用步骤 UIButton的代码创建与常用属性设置 重写按钮的某个状态属性的 setter ...
- boot2docker安装及使用
更新homebrew 为了确保有boot2docker的安装脚本 brew update 安装boot2docker brew install boot2docker 初始化 boot2docker ...
- gem 'logstash-devutils'
需求 为了开发新的 logstash 插件 问题 原以为只是很简单的 bundle install 就能搞定的事情,实际却遇到了一堆问题. 1. clone git git@github.com:lo ...
- css模块化思想(一)--------命名是个技术活
引子: 女孩子都喜欢买衣服,而我也不例外,奈何钱包太瘦,买不起高大上的定制,只能买撞衫率极高的休闲衣,不过对于我来说,我还是开心的,毕竟买衣服买的不仅是衣服,更是一种心情.在web前端的世界里,css ...
- jQuery mouseover与mouseenter,mouseout与mouseleave的区别
mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. mouseou ...
- float保留7位double保留15位之后的数字四舍五进
public class $66 { public static void main(String agrs[]) { float a=(float) 1.123456789;//8位 System. ...
- JAXB - Validate Document before It is Unmarshalled
Validation A considerable part of the XML Schema language deals with facets, enabling the programmer ...
- activiti源码解读之心得整编
TaskService.completeTask()的执行内幕是啥? activiti采取了command模式,completeTask会被包装成一个CompleteTaskCmd,一个Cmd执行的时 ...
- Java的内存泄漏_与C/C++对比(转载总结)
原文网址:http://developer.51cto.com/art/201111/302465.htm Java内存泄露的理解与解决(1) 一般来说内存泄漏有两种情况.一种情况如在C/C++ ...