题意 : 给你一个凸多边形,让你在其中找两个圆,使得圆的覆盖面积最大。

这个题目和 poj 3525 有点类似,那个题目是一个圆,想到两者的联系,可以发现两个圆覆盖面积最大就是重叠面积最小,怎样使得重叠面积最小呢 ? 肯定就是两个圆心的圆心距最大,这样就可以了,先将边向内部缩 R (半径大小)求一个半平面交,然后在半平面交上找到距离最远的两个点就可以了。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define PI 3.1415926using namespace std;
#define N 1005
const double eps=1e-8;
int dcmp(double x) {if (x<=eps&&x>=-eps) return 0;return (x>0)?1:-1;
}
struct Vector {double x,y;Vector(double X=0,double Y=0){x=X,y=Y;}
};
typedef Vector Point;double dist (Point a,Point b) {return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}struct Line {Point p;Vector v;double ang;Line(Point P=Point(0,0),Vector V=Vector(0,0)) {p=P,v=V;ang=atan2(v.y,v.x);}bool operator < (const Line &a) const {return ang<a.ang;}
};
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 b) {return Vector(a.x*b,a.y*b);}int n,l,r,cnt;
double ans;
Line L[N],q[N];
Point p[N],poly[N];
double Cross(Vector a,Vector b) {return a.x*b.y-a.y*b.x;
}
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;
}
bool Onleft(Line m,Point P) {Vector w=P-m.p;return dcmp(Cross(m.v,w))>=0;
}
void halfp(){sort(L+1,L+n+1);cnt=0;q[l=r=1]=L[1];for (int i=2;i<=n;++i) {while (l<r&&!Onleft(L[i],p[r-1])) --r;while (l<r&&!Onleft(L[i],p[l])) ++l;q[++r]=L[i];if (dcmp(Cross(q[r].v,q[r-1].v))==0) {--r;if (Onleft(q[r],L[i].p))q[r]=L[i];}if (l<r)p[r-1]=GLI(q[r-1].p,q[r-1].v,q[r].p,q[r].v);}while (l<r&&!Onleft(q[l],p[r-1]))--r;if (r-l<=1) return;p[r]=GLI(q[r].p,q[r].v,q[l].p,q[l].v);for (int i=l;i<=r;++i) poly[++cnt]=p[i];
}
double Area() {double ans=0;for (int i=2;i<cnt;++i)ans+=Cross(poly[i]-poly[1],poly[i+1]-poly[1]);return fabs(ans/2);
}int main() {double R;while(scanf("%d%lf",&n,&R) != EOF) { // 输入点的个数Point temp[N],temp0,temp1;Line LL[N];Point pp[N];double ang[N];for (int i=1;i<=n;++i) {double x,y;scanf ("%lf%lf",&x,&y);pp[i] = Point (x,y);} // 开始需要设置一个无限大的区域pp[n + 1] = pp[1];for (int i = n + 1;i >= 2 ; -- i) {LL[i - 1] = Line(pp[i - 1],pp[i - 1] - pp[i]);}temp[1] = pp[1];L[1] = LL[n];ang[1] = L[1].ang;for (int i = 2;i <= n; ++ i) {L[i] = LL[n + 1 - i];temp[i] = pp[n + 2 - i];ang[i] = L[i].ang;}temp[n + 1] = temp[1];L[++n] = Line(Point(-10000,10000),Vector(0,-10000));L[++n] = Line(Point(-10000,-10000),Vector(10000,0));L[++n] = Line(Point(10000,-10000),Vector(0,10000));L[++n] = Line(Point(10000,10000),Vector(-10000,0));for (int i = 1;i <= n - 4; ++ i) {temp0 = temp[i];temp1 = temp[i + 1];double angd = ang[i] + PI / 2.0;
//            printf ("%.6f\n",angd);double addx = R * cos (angd);double addy = R * sin (angd);temp0.x += addx,temp1.x += addx;temp1.y += addy,temp0.y += addy;L[i] = Line(temp0,temp1 - temp0);}halfp();int id1 = 1,id2 = 1;double ans = 0;for (int i = 1;i <= cnt; ++ i) {
//            printf ("%.6f %.6f\n",poly[i].x,poly[i].y);for (int j = i + 1;j <= cnt ;++ j) {if (dist (poly[i],poly[j]) > ans) {ans = dist(poly[i],poly[j]);id1 = i;id2 = j;}}}printf ("%.6f %.6f %.6f %.6f\n",poly[id1].x,poly[id1].y,poly[id2].x,poly[id2].y);}return 0;
}

POJ 3384 Feng Shui(半平面交)相关推荐

  1. poj 3384 Feng Shui (Half Plane Intersection)

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

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

    链接 Feng Shui 题意 将两个半径为 rrr 的圆放入一个多边形中,两个圆占据最大面积时圆心坐标是多少: 思路 在多边形中放圆,最大圆的圆心一定在多边形内核中: 将多边形的每条边都内推 rrr ...

  3. POJ 3384 Feng Shui

    坑爹的题,,就是先向内推进r,然后半平面交得出圆心范围. 然后旋转卡壳求最远点对 这道题首先样例给的就不对,不知道什么情况 然后一直WA,后来看了discuss,试了下这组数据: 4 1 0 0 0 ...

  4. CodeForces - Feng Shui(半平面交)

    题目链接:http://codeforces.com/gym/101650/attachments Time Limit: 2000MS Memory Limit: 65536K Descriptio ...

  5. poj 3384 Feng Shui 半平面交

    http://poj.org/problem?id=3384 给定一个多边形,在多边形内放有两个相同的圆,使两个圆尽可能多的覆盖多边形.输出最终两个圆心的位置. 最优的放置方法必定是圆内切于两条边,那 ...

  6. poj 1755 Triathlon (半平面交解一元二次不等式)(切割求半平面交)

    题目链接:哆啦A梦传送门 参考链接:https://blog.csdn.net/acm_cxlove/article/details/7883370 半平面交模板 题目:铁人三项,每个人在某一项中有确 ...

  7. POJ 1755 Triathlon(半平面交)

    题目链接:http://poj.org/problem?id=1755 题意:一段距离总长度为L,将L分成三部分a,b和c(a.b.c均大于0).有N(1 <= N <= 100) 个人, ...

  8. POJ 2540 Hotter Colder(半平面交求可行域)

    转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove 题目:从0,0出发,走到某一点, ...

  9. POJ 1279 Art Gallery 半平面交 多边形的核

    题意:求多边形的核的面积 套模板即可 #include <iostream> #include <cstdio> #include <cmath> #define ...

最新文章

  1. 我用Python爬取英雄联盟的皮肤,隔壁家的小弟弟都馋哭了
  2. undefined reference to '__gxx_personality_v0'
  3. 使用第三方《UITableView+FDTemplateLayoutCell》自动计算UITableViewCell高度(Masonry约束)...
  4. Android之library class android.webkit.WebViewClient depends on program class android.net.http.SslErro
  5. 数据结构 顺序表的建立+折半查找(二分查找)
  6. macOS Recovery中修复磁盘的具体操作方法
  7. Remoting示例
  8. [Soft]软件技术的两个趋势
  9. 什么软件可以搜索python答案_【python学习手记】网课精灵~调用爬虫搜索网课答案~...
  10. 支付宝宣布刷脸支付将全面接管扫码支付
  11. [OpenCV+VS2015]火焰检测算法(HSI判据)
  12. [水晶报表]水晶报表的使用经验和资料总结
  13. 服务器打完补丁无法进入系统,win7系统电脑更新补丁后无法进入系统怎么办
  14. css绘制等边三角形
  15. H5 微信小游戏群 openGID 解密
  16. 普通网站的建设和维护费用大概是多少?
  17. 【诗词】曹雪芹:红豆词
  18. python实现pdf转png(转载)
  19. DNS云学堂 | 智能DNS让CDN乘风破浪
  20. 【pwn-栈溢出】— ret2plt

热门文章

  1. 2019电赛纸张计数仪分析——————致敬“谢谢惠顾”
  2. 怎样更改计算机网络密码怎么办,wifi密码怎么改?
  3. 基于Java的SMTP协议邮件发送模拟系统
  4. 亚信科技中国有限公司实习面试(长春)
  5. 关于字符串中加入变量的方式
  6. insmod过程详解
  7. 【GANs】C-RNN-GAN
  8. H5图片切换,js图片轮播,js图片自动切换
  9. 国产热门操作系统Deepin试用感受
  10. C/C++描述 LeetCode周赛 5473. 灯泡开关 IV