题意

给出原点(不是(0,0)那个原点)的坐标和一个多边形的顶点坐标,求多边形绕原点转一圈扫过的面积(每个顶点到原点距离保持不变)。

分析

多边形到原点的最小距离和最大距离构成的两个圆之间的圆环就是所求面积。

判断最大距离一定在顶点上,最小距离可能在点上也可能在边上。

如果原点到一个顶点的连线和它所在的边构成钝角,那么最小距离在点上,否则最小距离就是顶点和该边构成三角形的原点所在的高,可以用海伦公式求三角形面积,然后求高。

不过我用的方法是点到直线的距离公式。

然后π用 acos(-1.0) 表示。

代码

#include <stdio.h>
#include<iostream>
#include <cmath>
#define dd double
using namespace std; int n;
dd far,nea=1e19,t,P=acos(-1.0); struct po
{
double x,y;
} p[]; dd P_P(po a,po b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} dd P_L(po a,po b,po c)//point c --> line ab
{
dd l1=P_P(a,b);
dd l2=P_P(a,c);
dd l3=P_P(b,c); if(l2*l2 >= (l1*l1+l3*l3))
return l3; if(l3*l3>=(l2*l2+l1*l1))
return l2; dd A=a.y-b.y;
dd B=b.x-a.x;
dd C=a.x*b.y - a.y*b.x;
//line ab: Ax+By+C=0;
dd D=A*c.x + B*c.y + C; return fabs(D*D/(A*A+B*B));
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y); for(int i=;i<=n;i++)
{
if (i<n) nea = min( P_L(p[i], p[i+], p[]), nea);
else nea = min( P_L(p[n], p[], p[]), nea); far=max(far,P_P(p[],p[i]));
}
printf("%.18lf\n",P*(far-nea)); return ;
}

  

【CodeForces 613A】Peter and Snow Blower的更多相关文章

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

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

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

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

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. codeforce #339(div2)C Peter and Snow Blower

    Peter and Snow Blower 题意:有n(3 <= n <= 100 000)个点的一个多边形,这个多边形绕一个顶点转动,问扫过的面积为多少? 思路:开始就认为是一个凸包的问 ...

  6. A. Peter and Snow Blower 解析(思維、幾何)

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

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

  8. 【codeforces 768C】Jon Snow and his Favourite Number

    [题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...

  9. 【Codeforces 947B】 Producting Snow

    [题目链接] 点击打开链接 [算法] 前缀和 + 堆 [代码] #include<bits/stdc++.h> using namespace std; typedef long long ...

随机推荐

  1. leetcode-Spiral Matrix II 螺旋矩阵2之python大法好,四行就搞定,你敢信?

    Spiral Matrix II 螺旋矩阵 Given an integer n, generate a square matrix filled with elements from 1 to n2 ...

  2. NGUI OnChange Event

    那些组件有OnChange? 下面这些组件都有OnChange事件,当你点击,下拉选择时,就会触发它们. NGUI中对应的组件 PopupList (下拉列表) Toggle (复选框) Input ...

  3. import javax.servlet.FilterConfig;

    具体的使用方法你可以在google上搜索 “filter 过滤器”,FilterConfig可以获取部署描述符文件(web.xml)中分配的过滤器初始化参数.针对你的问题回答,结果就是说FilterC ...

  4. bean的作用域

    bean的作用域为singleton,spring容器中只存在一个bean的实例,所有对该bean的请求只返回同一个bean实例. 当bean的作用域为prototype时,每一次对bean的请求,都 ...

  5. The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  6. javarebel热部署 (转)

    Java web开发部署效率浅析 在进行java web程序开发过程中,经常遇到这种问题,修改一个java文件(*.java),需要重启web服务器(如tomcat,weblogic等),部署项目.而 ...

  7. mysql-5.7.14-winx64免安装版在win10下的详细配置过程

    1.配置文件 如果使用mysql的默认配置,在使用的过程中会出现很多问题,如汉字是乱码等. 在mysql的根目录(如:D:\mysql\mysql-5.7.14-winx64\)下,新建配置文件my. ...

  8. JS 之继承

    ECMAScript继承是通过原型链来继承的.基本思想是利用原型来让一个引用类型继承另一个引用类型的属性和方法,使原型变为另一个对象的实例.通过原型链实现继承时,不能使用对象字面量创建原型方法,避免重 ...

  9. 2016北京PHP39期 ThinkPHP Discuz Dedecms 微信开发视频教程

    2016北京PHP39期 ThinkPHP Discuz Dedecms 微信开发视频教程 所有项目均带有软件,笔记,视频,源码 日期   课程(空内容代表放假) 2015/7/10 星期五 开学典礼 ...

  10. opencv2学习:计算协方差矩阵

    图像的高级处理中,协方差矩阵计算是必不可少的,但opencv关于这方面的资料却相当少. 首先,利用matlab计算一下,便于比较: >> data=[1,2,3;10,20,30] dat ...