POJ 3384 Feng Shui --直线切平面
题意:房间是一个凸多边形,要在里面铺设两条半径为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 --直线切平面的更多相关文章
- poj 3384 Feng Shui (Half Plane Intersection)
3384 -- Feng Shui 构造半平面交,然后求凸包上最远点对. 这题的题意是给出一个凸多边形区域,要求在其中放置两个半径为r的圆(不能超出凸多边形区域),要求求出两个圆心,使得多边形中没有被 ...
- POJ 3384 Feng Shui (半平面交)
Feng Shui Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3743 Accepted: 1150 Speci ...
- POJ 3384 Feng Shui 半平面交
题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...
- POJ 3384 Feng Shui(计算几何の半平面交+最远点对)
Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achie ...
- POJ 3384 Feng Shui
http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最 ...
- POJ 3384 Feng Shui(半平面交向内推进求最远点对)
题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...
- POJ 3384 Feng Shui 凸包直径 + 半平面交
G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...
- poj 3384 半平面交
Feng Shui Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5183 Accepted: 1548 Speci ...
- poj 3304线段与直线相交
http://poj.org/problem?id=3304 Segments Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
随机推荐
- 用js动态生成css代码
有时候我们需要利用js来动态生成页面上style标签中的css代码,方法很直接,就是直接创建一个style元素,然后设置style元素里面的css代码,最后把它插入到head元素中.但有些兼容性问题我 ...
- HTML5拖放(drag and drop)与plupload的懒人上传
HTML5拖放能够将本地的文件拖放到页面上,plupload又是很好的文件上传插件,而今天就将两者结合,做了个文件拖拽上传的功能. 简述HTML5拖放 拖放是HTML5标准的一部分,任何元素都能够拖放 ...
- git和svn
git 分布式管理工具 svn 集中式管理工具 1. Git是分布式的,SVN是集中式的,好处是跟其他同事不会有太多的冲突,自己写的代码放在自己电脑上,一段时间后再提交.合并,也可以不用联网在本地提交 ...
- JavaScript中使用typeof运算符需要注意的几个坑
typeof是一个运算符,它对操作数返回的结果是一个字符串,有6种(只针对ES,不包含HOST环境对象). 1.'undefined'2.'boolean'3.'string'4.'number'5. ...
- 每天checklist所用到的T-CODE
1.1重点检查 作业 事务码 检查过程 检查R/3系统是否已经启动 · 登录到R/3系统 检查每日备份是否正常 DB12-Backup Logs:Overview · 检查数据库备份 · 检查数据库备 ...
- Oracle中用随机数更新字段----将一张表的数据插入另一张表----环境设置
DECLARE CURSOR recordCursor IS SELECT longitude,latitude FROM WR_WIUST_B_SEC FOR UPDATE; recordRow r ...
- php强制转换类型和CMS远程管理插件的危险
远程管理插件是十分受WordPress站点管理员欢迎的工具,它们允许用户同时对多个站点执行相同的操作,如,更新到最新的发行版或安装插件.然而,为了实现这些操作,客户端插件需要赋予远程用户很大的权限.因 ...
- 无插件的大模型浏览器Autodesk Viewer开发培训-武汉-2014年8月28日 9:00 – 12:00
武汉附近的同学们有福了,这是全球第一次关于Autodesk viewer的教室培训. :) 你可能已经在各种场合听过或看过Autodesk最新推出的大模型浏览器,这是无需插件的浏览器模型,支持几十种数 ...
- SPS中使用JSOM发邮件
直接上代码了: function ShowMailDialog() { $.ajax({ url: siteurl + "/_api/contextinfo", method: & ...
- 【iOS】网络编程:上传图片到服务器
在网络编程中,如果需要上传图片,那么他的方法将会和普通的上传数据不同,下面将讲解如何上传图片. 环境信息: Mac OS X 10.9.5 Xcode 5.1.1 IOS 7.1 正文: - (NSU ...