题意

给出原点(不是(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. redis 一二事 - 搭建集群缓存服务器

    在如今并发的环境下,对大数据量的查询采用缓存是最好不过的了,本文使用redis搭建集群 (个人喜欢redis,对memcache不感冒) redis是3.0后增加的集群功能,非常强大 集群中应该至少有 ...

  2. java 10-4 Scanner方法

    Scanner:用于接收键盘录入数据  常用的两个方法(int举例): public int nextInt():获取一个int类型的值 public String nextLine():获取一个St ...

  3. C# WinForm 中Console 重定向输出到ListBox控件中显示

                        {              VoidAction action =              {                  lstBox.Items. ...

  4. Javascript的变量与delete操作符

    原文:http://charlee.li/javascript-variables-and-delete-operator.html 刚刚看到一篇好文(原文链接), 对Javascript中的dele ...

  5. 21Mybatis_订单商品数据模型_一对多查询——resultMap方式

    这篇文章延续订单商品数据模型,这张讲述的是一对多的查询.(用resultMap) 给出几张表的内容: User表:

  6. 关闭linux centos各种声音

    shell报警 #vi /etc/inputrc ================================ set bell-style none 或 echo "set bell- ...

  7. LinkedList方法总结 ListIterator和Iterator的区别

    LinkedList也像ArrayList一样实现了基本的接口,但是它执行某些从操作时比ArrayList更高效,但在随机访问方面要逊色一些.LinkedList中有一些方法虽然名字不同,但可以完成相 ...

  8. 《WCF服务编程第三版》知识点摘录

  9. linux修改网卡名称

    本文转载自江一<linux修改网卡名称> 终端输入:vi /etc/udev/rules.d/70-persistent-net.rules 出现以下文件 # This file was ...

  10. [CareerCup] 5.8 Draw Horizonatal Line 画横线

    5.8 A monochrome screen is stored as a single array of bytes, allowing eight consecutive pixels to b ...