题面

题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少

题解:三分套三分求出圆心位置,再用圆与多边形面积求交

 #include<bits/stdc++.h>
#define inf 1000000000000
#define M 100009
#define eps 1e-12
#define PI acos(-1.0)
using namespace std;
struct node
{
double x,y;
node(){}
node(double xx,double yy)
{
x=xx;
y=yy;
}
node operator -(node s)
{
return node(x-s.x,y-s.y);
}
node operator +(node s)
{
return node(x+s.x,y+s.y);
}
double operator *(node s)
{
return x*s.x+y*s.y;
}
double operator ^(node s)
{
return x*s.y-y*s.x;
}
}p[M],a[M];
double max(double a,double b)
{
return a>b?a:b;
}
double min(double a,double b)
{
return a<b?a:b;
}
double len(node a)
{
return sqrt(a*a);
}
double dis(node a,node b)//两点之间的距离
{
return len(b-a);
}
double cross(node a,node b,node c)//叉乘
{
return (b-a)^(c-a);
}
double dot(node a,node b,node c)//点乘
{
return (b-a)*(c-a);
}
int judge(node a,node b,node c)//判断c是否在ab线段上(前提是c在直线ab上)
{
if(c.x>=min(a.x,b.x)
&&c.x<=max(a.x,b.x)
&&c.y>=min(a.y,b.y)
&&c.y<=max(a.y,b.y))
return ;
return ;
}
double area(node b,node c,double r)
{
node a(0.0,0.0);
if (dis(b,c)<eps) return 0.0;
double h=fabs(cross(a,b,c))/dis(b,c);
if(dis(a,b)>r-eps&&dis(a,c)>r-eps)//两个端点都在圆的外面则分为两种情况
{
double angle=acos(dot(a,b,c)/dis(a,b)/dis(a,c));
if(h>r-eps)
{
return 0.5*r*r*angle;
}
else if(dot(b,a,c)>&&dot(c,a,b)>)
{
double angle1=*acos(h/r);
return 0.5*r*r*fabs(angle-angle1)+0.5*r*r*sin(angle1);
}
else
{
return 0.5*r*r*angle;
}
}
else if(dis(a,b)<r+eps&&dis(a,c)<r+eps)//两个端点都在圆内的情况
{
return 0.5*fabs(cross(a,b,c));
}
else//一个端点在圆上一个端点在圆内的情况
{
if(dis(a,b)>dis(a,c))//默认b在圆内
{
swap(b,c);
}
if(fabs(dis(a,b))<eps)//ab距离为0直接返回0
{
return 0.0;
}
if(dot(b,a,c)<eps)
{
double angle1=acos(h/dis(a,b));
double angle2=acos(h/r)-angle1;
double angle3=acos(h/dis(a,c))-acos(h/r);
return 0.5*dis(a,b)*r*sin(angle2)+0.5*r*r*angle3; }
else
{
double angle1=acos(h/dis(a,b));
double angle2=acos(h/r);
double angle3=acos(h/dis(a,c))-angle2;
return 0.5*r*dis(a,b)*sin(angle1+angle2)+0.5*r*r*angle3;
}
}
}
int n;
double x,y,h,x1,yy,R;
double gets(node O)//求圆与多边形面积并
{
for (int i=;i<=n+;i++) p[i]=a[i];
for(int i=;i<=n+;i++) p[i]=p[i]-O;
O=node(,);
double sum=;
for(int i=;i<=n;i++)
{
int j=i+;
double s=area(p[i],p[j],R);
if(cross(O,p[i],p[j])>) sum+=s; else sum-=s;
}
return fabs(sum);
}
int dcmp(double x)
{
if(x > eps) return ;
return x < -eps ? - : ;
}
double calc(double x)
{
double l=,r=-,m1,m2,f1=,f2=;
for (int i=;i<=n;i++)
{
if (dcmp((a[i].x-x) * (a[i+].x-x))<=)
{
node tmp;
tmp.x=a[i].x+(a[i+].x-a[i].x)/(a[i+].x-a[i].x)*(x-a[i].x);
tmp.y=a[i].y+(a[i+].y-a[i].y)/(a[i+].x-a[i].x)*(x-a[i].x);
l=min(l,tmp.y);
r=max(r,tmp.y);
}
}
while (l+eps<r)
{
m1=(l+l+r)/3.0;
node bom=node(x,m1);
f1=gets(bom);
m2=(l+r+r)/3.0;
bom=node(x,m2);
f2=gets(bom);
if (f1>f2) r=m2;else l=m1;
}
return f1;
}
int main()
{
scanf("%d%lf",&n,&R);
double l=,r=-,m1,m2,f1,f2;
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
l=min(l,a[i].x);
r=max(r,a[i].x);
}
a[n+]=a[];
while (l+eps<r)
{
m1=(l+l+r)/3.0;f1=calc(m1);
m2=(l+r+r)/3.0;f2=calc(m2);
if (f1>f2) r=m2;else l=m1;
}
printf("%.6lf\n",f1);
return ;
}

Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交的更多相关文章

  1. Gym101158 J 三分 or 模拟退火 Cover the Polygon with Your Disk

    目录 Gym101158 J: 求圆与给定凸多边形最大面积交 模拟退火 三分套三分 模拟退火套路 @ Gym101158 J: 求圆与给定凸多边形最大面积交 传送门:点我点我 求 $10 $ 个点组成 ...

  2. Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】

    J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...

  3. Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积

    Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...

  4. Gym - 100851A Adjustment Office(O(1)求行列和)

    Adjustment Office Gym - 100851A 2       3       4 3       4       5 4       5       6 n<=10^6,q&l ...

  5. Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交

    题面 题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交 题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交 打的时候队友说凹的不行,不是板题,后面想想,圆与多 ...

  6. HDU 5130 Signal Interference(计算几何 + 模板)

    HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...

  7. HDU - 3642 Get The Treasury(线段树求体积交)

    https://cn.vjudge.net/problem/HDU-3642 题意 求立方体相交至少3次的体积. 分析 三维的呢..首先解决至少覆盖三次的问题.则用三个标记,更新时的细节要注意. 注意 ...

  8. 2018.07.03 POJ 1279Art Gallery(半平面交)

    Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...

  9. Gym - 101982F Rectangles (扫描线+线段树)

    链接:http://codeforces.com/gym/101982/attachments 思路: 问被覆盖次数为奇数次的矩阵的面积并 扫描线求矩阵面积并我们是上界赋为-1,下界赋为1,因为要求覆 ...

随机推荐

  1. Memcached 之缓存雪崩现象、实际案例和缓存无底洞现象

    一.缓存雪崩现象 由于集群中某个memcached服务器宕机的原因,造成集群中的服务器命中率下降.只能通过访问数据库得到数据,是的数据库的压力倍增,造成数据库服务器崩溃.重启数据库还是会崩溃,但是数据 ...

  2. EMC VNX5200/5400存储 新增LUN与Hosts映射操作

    EMC VNX5200/5400 1.创建RAID  Groups 1.1        进入EMC VNX5200/5400主界面,依次选择Storage——Storage Pools——RAID ...

  3. 【转载】intellij idea如何将web项目打成war包

    1.点击[File]->[Project Structure]菜单(或使用Shift+Ctrl+Alt+S快捷键),打开[Project Structure]窗口.如下图: 2.在[Projec ...

  4. C#第九节课

    try catch using System;using System.Collections.Generic;using System.Linq;using System.Text;using Sy ...

  5. C++ 对象创建的问题

    一.C++对象的创建: 对象创建的注意事项: 1.对象数组里的个数,就是创建对象的个数,普通数组一样:下标从0 到数组里数字 -1: 2.类名*  对象指针   <-->  这里只是一个指 ...

  6. ecshop3 调用指定分类下推荐/热卖/新品商品,可指定调用数量

    第一步:--------------------------------------------------------------------------------------/** * 取指定分 ...

  7. (27)Spring Boot Junit单元测试【从零开始学Spring Boot】

    Junit这种老技术,现在又拿出来说,不为别的,某种程度上来说,更是为了要说明它在项目中的重要性. 那么先简单说一下为什么要写测试用例 1. 可以避免测试点的遗漏,为了更好的进行测试,可以提高测试效率 ...

  8. CentOS 6.3(x86_32)下安装Oracle 10g R2

    一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...

  9. 0320SQL中的where条件,在数据库中提取与应用浅析

    转自 何登成的技术博客 追求技术的道路上,10年如一日     首页 关于我 RSS 订阅 © 2012-2017 何登成的技术博客   SQL中的where条件,在数据库中提取与应用浅析 3月 3r ...

  10. ubuntu-ln命令

    安装软件完成后,常常需要使用ln命令来将命令重新定义一下路径,就相当于windows中的加入系统环境变量的意思 ~ sudo ln -s /home/spike/Downloads/redis/src ...