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. 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.
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.
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
.
3 0 0
0 1
-1 2
1 2
12.566370614359172464
4 1 -1
0 0
1 2
2 0
1 1
21.991148575128551812
几何题做的不多呢 这次算是对自己的检验
题意很简单 就是找多边形上距离旋转中心的最远点和最近点 然后大圆面积减小圆面积
最远点必定在点上 最近点则可能在边上
更新最近点时 取相邻两点和旋转中心构成三角形 用余弦定理判断这两个点对应的角是否钝角 换句话说最近点是否在相邻两点间
如果有钝角 直接取两点到中心距离近的那个 如果没有 用海伦公式算高
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
#define PI 3.1415926535898
using namespace std; struct Node{
double x, y;
}node[]; double DISTANCE(int a, int b){
return sqrt((node[a].x - node[b].x) * (node[a].x - node[b].x)
+ (node[a].y - node[b].y) * (node[a].y - node[b].y));
} int main()
{
int n;
double up, down, s;
scanf("%d%lf%lf", &n, &node[].x, &node[].y);
up = ; down = 1e20;
for(int i = ; i <= n; i++){
scanf("%lf%lf", &node[i].x, &node[i].y);
up = max(DISTANCE(i, ), up);
}
for(int i = ; i < n; i++){
double a = DISTANCE(, i);
double b = DISTANCE(, i + );
double c = DISTANCE(i, i + );
if(a*a + c*c - b*b < || b*b + c*c - a*a < ){
down = min(down, min(a, b));
}
else{
double p = (a + b + c) / ;
down = min(down, * sqrt(p * (p - a) * (p - b) * (p - c)) / c);
}
}
{
double a = DISTANCE(, );
double b = DISTANCE(, n);
double c = DISTANCE(, n);
if(a*a + c*c - b*b < || b*b + c*c - a*a < ){
down = min(down, min(a, b));
}
else{
double p = (a + b + c) / ;
down = min(down, * sqrt(p * (p - a) * (p - b) * (p - c)) / c);
}
}
s = ((up * up) - (down * down)) * PI;
printf("%.16lf\n", s);
//printf("up = %lf down = %lf\n", up, down);
return ;
}
Codeforces Round #339 Div.2 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 ...
- Codeforces Round #339 (Div.2)
A. Link/Cut Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #339 (Div. 2) B. Gena's Code 水题
B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题
A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- Codeforces Round #339 (Div. 1) B. Skills 暴力 二分
B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...
- Codeforces Round #339 Div.2 B - Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...
- Codeforces Round #339 Div.2 A - Link/Cut Tree
第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ // ...
- Codeforces Round #339 (Div. 2) A
Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which ...
随机推荐
- cf--1C
//Accepted 0 KB 60 ms //给出正多变形上的三个点,求正多形的最小面积 //记三个点之间的距离a,b,c; //由余弦定理得cosA //从而可求出sinA,和正多边形所在外接圆的 ...
- VS2013 JS 跟踪
VS2013JS 跟踪 1.在页面对应的cs文件中设置断点,F10单步执行. 2.单步执行调试会自然而然执行到JS里面.
- Python入门(四,高级)
一,面向对象 面向对象技术简介 类(Class): 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. 类变量:类变量在整个实例化的对象中是公用的. ...
- yii2 数据验证
控制器层 <?php namespace frontend\controllers; use Yii; use frontend\models\FormsModel; use yii\web\U ...
- WinFrm窗体的传值方式
比较简单的方法: 一:1.定义两个窗体 2.在父窗体中加入子窗体的属性 public ChildFrm ChildFrm { get; set; } 3.加载的时候: private void Par ...
- HDU 4971 (最小割)
Problem A simple brute force problem (HDU 4971) 题目大意 有n个项目和m个问题,完成每个项目有对应收入,解决每个问题需要对应花费,给出每个项目需解决的问 ...
- WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
WPF入门教程系列(二) 深入剖析WPF Binding的使用方法 同一个对象(特指System.Windows.DependencyObject的子类)的同一种属性(特指DependencyProp ...
- Magneto插件整理
以connect20.magentocommerce.com开头的是connect 2.0的key.有些网页打不开了.但是connect的地址经测试是可用的. Mangento 免费团购模块 http ...
- MapBox TileMill
TileMill 学习网站: Walkthrough: Creating tiles with Mapnik using TileMill TileMill 快速入门 Cartography With ...
- 设计模式:Strategy 策略模式 -- 行为型
设计模式 策略模式Strategy(对象行为型) 这是几年前写的文字(转载做的笔记更准确些),发觉还是废话多了点. 其实,核心就是5.结构中的UML图 5.1 和 5.2(新增).现在看这张图就觉得一 ...