codeforces 614 C Peter and Snow Blower

C. Peter and Snow Blower
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.

Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.

Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him.

Input

The first line of the input contains three integers — the number of vertices of the polygon n (), and coordinates of point P.

Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.

All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.

Output

Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .



#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define inf 1000000000000000
#define LL long long  
using namespace std;

/************************************************ 
 
Desiner:hl 
time:2016/02/05 
Exe.Time:93 ms
Exe.Memory:1600 KB 

题目链接:http://codeforces.com/contest/614/problem/C

题意:例子解释的很清楚 


题解:我只能呵呵了。。。精度问题。精度问题。精度问题 
求的是点到一个几何体的最短和最长距离 
我用的向量方法解。用向量积算出角度,然后再算出点到线的距离 
************************************************/  
double pi=asin(1)*2;
struct Point{
	double x;
	double y;
};

double caulen(Point p1,Point p2){
	double lenth = (p1.x-p2.x)*(p1.x-p2.x)*1.0+(p1.y-p2.y)*(p1.y-p2.y)*1.0;
	return lenth;
}

double cauPointToLine(Point o,Point p1,Point p2){
	double a=(p2.x-p1.x)*(o.x-p1.x)+(p2.y-p1.y)*(o.y-p1.y);
	if(a<0.0000001) return caulen(o,p1);
	double b=(p1.x-p2.x)*(o.x-p2.x)+(p1.y-p2.y)*(o.y-p2.y);
	if(b<0.0000001) return caulen(o,p2);
	double op1=caulen(o,p1);
	double p1p2=caulen(p1,p2);
	double consinjiao=a/(sqrt(p1p2)*sqrt(op1));
	double jiao=acos(consinjiao);
	double ans=sqrt(op1)*sqrt((1-consinjiao*consinjiao));
	return ans*ans;
}



int main(){
	
	
	int i,j,k,l,n,m;
	Point o,a[100111];
	//这里minlen不能用inf赋值。。因为后面的数都比这个inf大。 
	double maxlen=0,minlen=0,len;
	scanf("%d",&n);
	//这里读入不能用int读。会有比int大的 
	scanf("%lf%lf",&o.x,&o.y);
	for(i=0;i<n;i++){
		//这里也是 
		scanf("%lf%lf",&a[i].x,&a[i].y);
	}
	for(i=0;i<n;i++){
		len=cauPointToLine(o,a[i],a[(i+1)%n]);
		if(minlen==0) minlen=len;
		minlen=minlen<len?minlen:len;
		maxlen=maxlen>len?maxlen:len;
	}
	//printf("%lf %lf\n",maxlen,minlen);
	for(i=0;i<n;i++){
		len = caulen(o,a[i]);
		maxlen=maxlen>len?maxlen:len;
		minlen=minlen>len?len:minlen;

	}
	//printf("%lf %lf\n",maxlen,minlen);
	double ans=(maxlen-minlen)*pi;
	printf("%.10lf\n",ans);
	return 0;
	
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值