POJ 3384 放地毯【半平面交】
<题目链接>
题目大意:
给出一个凸多边形的房间,根据风水要求,把两个圆形地毯铺在房间里,不能折叠,不能切割,可以重叠。问最多能覆盖多大空间,输出两个地毯的圆心坐标。多组解输出其中一个,题目保证至少可以放入一个圆。
解题分析:
因为放置的圆不能超出多边形的边界,所以先将该凸多边形的各个边长向内平移 r 的距离,然后对这些平移后的直线用半平面交去切割原多边形,切割后得到的区域就是两圆圆心所在的区域,然后遍历这个切割后的多边形的各个顶点,距离最远的两个顶点就是这两圆的圆心。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 10005 const double pi=acos(-1.0);
const double inf=1e9;
const double eps=1e-;
int dcmp(double x)
{
if (x<=eps&&x>=-eps) return ;
return (x>)?:-;
}
struct Vector
{
double x,y;
Vector(double X=,double Y=)
{
x=X,y=Y;
}
};
typedef Vector Point;
Vector operator + (Vector a,Vector b) {return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector b) {return Vector(a.x-b.x,a.y-b.y);}
Vector operator * (Vector a,double p) {return Vector(a.x*p,a.y*p);} int n,cnt,ncnt,ansi,ansj;
double x,y,r,ans;
Point p[N],poly[N],npoly[N]; double Dot(Vector a,Vector b)
{
return a.x*b.x+a.y*b.y;
}
double Cross(Vector a,Vector b)
{
return a.x*b.y-a.y*b.x;
}
double Len(Vector a)
{
return sqrt(Dot(a,a));
}
Vector rotate(Vector a,double rad)
{
return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
bool insLS(Point A,Point B,Point C,Point D)
{
Vector v=B-A,w=C-A,u=D-A;
return dcmp(Cross(v,w))!=dcmp(Cross(v,u));
}
Point GLI(Point P,Vector v,Point Q,Vector w)
{
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
}
void init()
{
cnt=;
poly[++cnt]=Point(inf,inf);
poly[++cnt]=Point(inf,-inf);
poly[++cnt]=Point(-inf,-inf);
poly[++cnt]=Point(-inf,inf);
}
void halfp(Point A,Point B)
{
ncnt=;
Point C,D;
for (int i=;i<=cnt;++i)
{
C=poly[i%cnt+];
D=poly[(i+)%cnt+];
if (dcmp(Cross(B-A,C-A))<=)
npoly[++ncnt]=C;
if (insLS(A,B,C,D))
npoly[++ncnt]=GLI(A,B-A,C,D-C);
}
cnt=ncnt;
for (int i=;i<=cnt;++i)
poly[i]=npoly[i];
}
int main()
{
scanf("%d%lf",&n,&r);
for (int i=;i<=n;++i)
{
scanf("%lf%lf",&x,&y);
p[i]=Point(x,y);
}
init();
for (int i=;i<=n;++i)
{
Point A=p[i%n+];
Point B=p[(i+)%n+];
Vector v=B-A;
Vector w=rotate(v,-pi/2.0);
w=w*(r/Len(w));
Point C=A+w;
Point D=C+v;
halfp(C,D);
}
ansi=ansj=;
for (int i=;i<=cnt;++i)
for (int j=i+;j<=cnt;++j)
{
double dis=Len(poly[i]-poly[j]);
if (dcmp(dis-ans)>)
{
ans=dis;
ansi=i,ansj=j;
}
}
printf("%.4lf %.4lf %.4lf %.4lf\n",poly[ansi].x,poly[ansi].y,poly[ansj].x,poly[ansj].y);
}
2018-08-03
POJ 3384 放地毯【半平面交】的更多相关文章
- 2018.07.03 POJ 1279Art Gallery(半平面交)
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...
- POJ 3335 Rotating Scoreboard 半平面交求核
LINK 题意:给出一个多边形,求是否存在核. 思路:比较裸的题,要注意的是求系数和交点时的x和y坐标不要搞混...判断核的顶点数是否大于1就行了 /** @Date : 2017-07-20 19: ...
- POJ 1474 Video Surveillance 半平面交/多边形核是否存在
http://poj.org/problem?id=1474 解法同POJ 1279 A一送一 缺点是还是O(n^2) ...nlogn的过几天补上... /********************* ...
- POJ 1279 Art Gallery 半平面交/多边形求核
http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...
- POJ 1279 Art Gallery 半平面交求多边形核
第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...
- POJ 1755 Triathlon (半平面交)
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4733 Accepted: 1166 Descrip ...
- POJ 1474 Video Surveillance(半平面交)
题目链接 2Y,模版抄错了一点. #include <cstdio> #include <cstring> #include <string> #include & ...
- POJ 1279 Art Gallery(半平面交)
题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...
- POJ 1279 Art Gallery 半平面交 多边形的核
题意:求多边形的核的面积 套模板即可 #include <iostream> #include <cstdio> #include <cmath> #define ...
随机推荐
- input框的输入限制
1.输入数字 <input onKeyUp="value=value.replace(/[^\d|chun]/g,'')"> 2.只输入中文 <input typ ...
- CSS3动画常用demo
1.border动画 2.闪动动画(一闪一闪亮晶晶,满天都是小星星) .blink { animation: mymove 0.8s infinite; -webkit-animation: mymo ...
- eclipse设置代码模板和格式
该设置可以在保存文件时自动根据模板调整代码格式. 首先准备华为代码格式化文件: FEFO-Formatter.xml FEFO-codetemplates.xml 设置格式Preferences-Ja ...
- 006_netstat中state详解
TCP三次握手的过程如下: 主动连接端发送一个SYN包给被动连接端: 被动连接端收到SYN包后,发送一个带ACK和SYN标志的包给主动连接端: 主动连接端发送一个带ACK标志的包给被动连接端,握手动作 ...
- Nodejs 实现ESL内联FreeSWITCH设定说明
一.背景说明: SIP Server IP (Centos):192.168.11.61 ,服务器IP(Windows):192.168.11.19 二.目的: 能够从192.168.11.19上通 ...
- Ex 5_21 无向图G=(V,E)的反馈边集..._第九次作业
根据题意,求的是最大生成树.利用Kruskal算法,对边进行从大到小的顺序进行排序,然后再依次取出边加入结果集中.假设图有n个顶点,那么,当结果集中有n-1条边时,剩下的边的集合即为反馈边集. pac ...
- Python-bootstrap
1 引入 如果想要用到BootStrap提供的js插件,那么还需要引入jQuery框架,因为BootStrap提供的js插件是依赖于jQuery的 <link type="text/c ...
- 测试开发之前端——No5.HTML5中的表单事件
表单事件 由 HTML 表单内部的动作触发的事件. 适用于所有 HTML 5 元素,不过最常用于表单元素中: 属性 值 描述 onblur script 当元素失去焦点时运行脚本 onchange s ...
- LeetCode(42):接雨水
Hard! 题目描述: 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水. 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度 ...
- LeetCode(34):搜索范围
Medium! 题目描述: 给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 你的算法时间复杂度必须是 O(log n) 级别. 如果 ...