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边形所有顶点,求圆环最小面积. 卡了好久,各种傻逼错误.. 题目就是让我们固定一大一小两个边界圆,我们来看看这两个圆满足什么条件. 首先外面 ...
随机推荐
- win7如何共享文件 图文教你设置win7文件共享
点评:win7文件共享已成为网友们之间的热议,接下来为大家分享下如何共享文件,首先开启guest账户( 开始菜单 → 运行 → services.msc → 双击 server 服务项 ,设置启动类型 ...
- IIS 之 失败请求跟踪规则
若想使用此功能需先启动如下图的Windows功能: 利用失败请求跟踪功能,可以在出现问题时捕获相应的XML格式的日志,从而无需重现该问题即可开始故障排除.此外,还可以定义应用程序的失败条件并配置要基于 ...
- python--while循环
1.最简单的while True循环 count = while True : : print('hello',count) break count += hello 2.利用while循环写一个猜年 ...
- Windows批处理(cmd/bat)常用命令小结
转载自:“趣IT”微信公共号 前言 批处理文件(batch file)包含一系列 DOS命令,通常用于自动执行重复性任务.用户只需双击批处理文件便可执行任务,而无需重复输入相同指令.编写批处理文件非常 ...
- 基于动态库的C++插件开发模型
基类为抽象类,在不同的动态库中实现不同的执行行为,但是每个动态库要提供2个统一的方法:1) baseClass * create(); 2) void destroy( baseClass* );,调 ...
- 快速集成图片浏览器快速集成图片浏览器->MJPhotoBrowser的使用
介绍: 一个比较完整的图片浏览器,高仿了新浪微博的图片浏览效果,功能包括:下载浏览互联网图片,点击缩略图全屏显示图片.当加载较大图片时会出现圆形进度条,滑动浏览所有图片.保存图片到本地相册.GIF图片 ...
- 【模拟】UVa 1030 - Image Is Everything
1030 - Image Is Everything Time limit: 3.000 seconds Your new company is building a robot that can h ...
- 까페24 호스팅 php 에러메세지 출력
[문제점] 최근 까페24호스팅에서 php작업시화면에 에러메세지가 나오지 않아 디버깅시에 매우 곤란함 [해결책] .htaccess 내용에 아래추가.=================== ...
- 第一个Servlet
一,第一个Servlet的编写过程 1,建立JavaWeb应用目录 HelloServlet--web应用名称 classes:Servlet就放在此处 lib web.xml 2,classes目录 ...
- h2database源码浅析:事务、两阶段提交
Transaction Isolation Transaction isolation is provided for all data manipulation language (DML) sta ...