题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大。

解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠。 那么我们把所有边都向内推进r,那么形成的多边形,可知两个圆形地毯的中心就一定在这个多边形边界上,最优的情况下是在此新凸包的最远点对上。

初始多边形为(-1000,-1000)到(1000,1000)的矩形,那么我们可以模拟把每条边都推进,每次切出新的凸多边形,然后得出最后的凸多边形,然后n^2枚举求最远点对即可。这里用到直线切割一个凸多边形的算法。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define Mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
using namespace std; struct Point{
double x,y;
Point(double x=, double y=):x(x),y(y) {}
void input() { scanf("%lf%lf",&x,&y); }
};
typedef Point Vector;
struct Line{
Point p;
Vector v;
double ang;
Line(){}
Line(Point p, Vector v):p(p),v(v) { ang = atan2(v.y,v.x); }
Point point(double t) { return Point(p.x + t*v.x, p.y + t*v.y); }
bool operator < (const Line &L)const { return ang < L.ang; }
};
int dcmp(double x) {
if(x < -eps) return -;
if(x > eps) return ;
return ;
}
template <class T> T sqr(T x) { return x * x;}
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); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }
bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
bool operator >= (const Point& a, const Point& b) { return a.x >= b.x && a.y >= b.y; }
bool operator <= (const Point& a, const Point& b) { return a.x <= b.x && a.y <= b.y; }
bool operator == (const Point& a, const Point& b) { return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ; }
double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
Vector VectorUnit(Vector x){ return x / Length(x);}
Vector Normal(Vector x) { return Point(-x.y, x.x) / Length(x);}
double angle(Vector v) { return atan2(v.y, v.x); } Point GetLineIntersection(Line A, Line B) {
Vector u = A.p - B.p;
double t = Cross(B.v, u) / Cross(A.v, B.v);
return A.p + A.v*t;
}
double DisP(Point A,Point B) {
return Length(B-A);
}
int LineCrossPolygon(Point& L1,Point& L2,Point* p,int n,Point* poly) {
int m = ;
for(int i=,j;i<n;i++) {
if(dcmp(Cross(L1-p[i],L2-p[i])) >= ) { poly[m++] = p[i]; continue; }
j = (i-+n)%n;
if(dcmp(Cross(L1-p[j],L2-p[j])) > ) poly[m++] = GetLineIntersection(Line(L1,L2-L1),Line(p[j],p[i]-p[j]));
j = (i++n)%n;
if(dcmp(Cross(L1-p[j],L2-p[j])) > ) poly[m++] = GetLineIntersection(Line(L1,L2-L1),Line(p[j],p[i]-p[j]));
}
return m;
} Line L[];
Point poly[][],p[],q1,q2;
int len[]; int main()
{
int i,j,pre,now,n;
double r;
while(scanf("%d%lf",&n,&r)!=EOF)
{
poly[][] = Point(-,-);
poly[][] = Point(,-);
poly[][] = Point(,);
poly[][] = Point(-,);
len[pre = ] = ;
for(i=;i<n;i++) p[i].input();
for(i=;i<n;i++) {
now = pre^;
Vector nv = Normal(p[i]-p[(i+)%n]);
q1 = p[i] + nv*r; q2 = q1+p[(i+)%n]-p[i];
len[now] = LineCrossPolygon(q2,q1,poly[pre],len[pre],poly[now]);
pre = now;
}
double Maxi = -Mod;
for(i=;i<len[now];i++)
for(j=i;j<len[now];j++) {
if(dcmp(DisP(poly[now][i],poly[now][j])-Maxi) > ) {
Maxi = DisP(poly[now][i],poly[now][j]);
q1 = poly[now][i], q2 = poly[now][j];
}
}
printf("%.6f %.6f %.6f %.6f\n",q1.x,q1.y,q2.x,q2.y);
}
return ;
}

POJ 3384 Feng Shui --直线切平面的更多相关文章

  1. poj 3384 Feng Shui (Half Plane Intersection)

    3384 -- Feng Shui 构造半平面交,然后求凸包上最远点对. 这题的题意是给出一个凸多边形区域,要求在其中放置两个半径为r的圆(不能超出凸多边形区域),要求求出两个圆心,使得多边形中没有被 ...

  2. POJ 3384 Feng Shui (半平面交)

    Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3743   Accepted: 1150   Speci ...

  3. POJ 3384 Feng Shui 半平面交

    题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...

  4. POJ 3384 Feng Shui(计算几何の半平面交+最远点对)

    Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achie ...

  5. POJ 3384 Feng Shui

    http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最 ...

  6. POJ 3384 Feng Shui(半平面交向内推进求最远点对)

    题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...

  7. POJ 3384 Feng Shui 凸包直径 + 半平面交

    G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...

  8. poj 3384 半平面交

    Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5183   Accepted: 1548   Speci ...

  9. poj 3304线段与直线相交

    http://poj.org/problem?id=3304 Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: ...

随机推荐

  1. 茎叶图(stem)

    介绍 茎叶图(Stem-and-Leaf display)又称“枝叶图”,由统计学家约翰托奇( Arthur Bowley)设计,它的思路是将数组中的数按位数进行比较,将数的大小基本不变或变化不大的位 ...

  2. Atitit.病毒木马的快速扩散机制原理nio 内存映射MappedByteBuffer

    Atitit.病毒木马的快速扩散机制原理nio 内存映射MappedByteBuffer 1. Java NIO(New Input/Output)1 1.1. 变更通知(因为每个事件都需要一个监听者 ...

  3. YARN的内存和CPU配置

    时间 2015-06-05 00:00:00  JavaChen's Blog 原文  http://blog.javachen.com/2015/06/05/yarn-memory-and-cpu- ...

  4. 超人学院二期学员分享hadoop工作经验

    定于2月17日--2月23日的某一天,邀请咱们学员分享一下hadoop工作经验.对于没工作过的同学或者没从事过hadoop工作的同学,抓住机会啊,你可以提前准备自己关心的各种问题! 具体时间请关注QQ ...

  5. CalloutManager

    在SharePoint中很多弹出的提示样式挺好看,不仅想整一个耍耍.如下图: 老办法,看一下html中的class名字得知为:Callout 谷歌之---官方文档:http://msdn.micros ...

  6. Xcode中XVim的常用操作

  7. 停止运行ExecutorService中的线程

    while(true){ try { sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch bloc ...

  8. 【代码笔记】iOS-手机号验证

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...

  9. iOS开发 - 兼容iOS 10

    1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至现在iOS 10开始真正的进行大改重构,这让开发者也体会到UserN ...

  10. 【好书摘要】性能优化中CPU、内存、磁盘IO、网络性能的依赖

    系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试了,以后就可以一劳永逸了,也不是说书本上 ...