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 ...
随机推荐
- Mac下压力测试工具siege
安装: brew install siege 用法: siege -c 并发数 -t 运行测试时间 URL 如: siege -c 1000 -t 5S URL 这里要注意的是-t后面的时间要带单位, ...
- oaracel 函数_行转列
wm_concat(varchar2) 组函数
- KERMIT,XMODEM,YMODEM,ZMODEM传输协议小结
转:http://blog.163.com/czblaze_3333/blog/static/208996228201272295236713/ Kermit协议 报文格式: 1. MAR ...
- linux更换yum源
由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源,以下为详细过程: 1.删除redhat原有的yum rpm - ...
- zabbix3.0.4安装grapha实现多台主机相同监控项集中展示
zabbix3.0.4安装grapha图形展示系统 操作系统 # cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 1.安装g ...
- Android:Service
Android Service: http://www.apkbus.com/android-15649-1-1.html android service 的各种用法(IPC.AIDL): http: ...
- Intellij IDEA14 搜索框及控制台乱码解决
搜索ctrl+F及ctrl+H的搜索框.调试的时候控制台.导入module都显示为为中文乱码 如下: 解决方案: File->Setting->IDE Settings->Appea ...
- 【必备】史上最全的浏览器 CSS & JS Hack 手册
[必备]史上最全的浏览器 CSS & JS Hack 手册 浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技 ...
- Arrange an Array to Form a Smallest Digit
/** * Input an array of positive integers, arrange the integers to form new digits, * and output the ...
- 步步为营-56-JQuery基础
jQuery本质还是封装好的js,只不过代码更简洁,而做的更好 使用JQuery选择器会返回一个jQuery对象,其本质是dom数组,jQuery对象可以调用JQuery方法. 1 选择器 1.1 基 ...