POJ 3384 Feng Shui (半平面交)
| Time Limit: 2000MS | Memory Limit: 65536K | |||
| Total Submissions: 3743 | Accepted: 1150 | Special Judge | ||
Description
Feng shui is the ancient Chinese practice of placement and arrangement of space to achieve harmony with the environment. George has recently got interested in it, and now wants to apply it to his home and bring harmony to it.
There is a practice which says that bare floor is bad for living area since spiritual energy drains through it, so George purchased two similar round-shaped carpets (feng shui says that straight lines and sharp corners must be avoided). Unfortunately, he is unable to cover the floor entirely since the room has shape of a convex polygon. But he still wants to minimize the uncovered area by selecting the best placing for his carpets, and asks you to help.
You need to place two carpets in the room so that the total area covered by both carpets is maximal possible. The carpets may overlap, but they may not be cut or folded (including cutting or folding along the floor border) — feng shui tells to avoid straight lines.
Input
The first line of the input file contains two integer numbers n and r — the number of corners in George’s room (3 ≤ n ≤ 100) and the radius of the carpets (1 ≤ r ≤ 1000, both carpets have the same radius). The following n lines contain two integers xi and yi each — coordinates of the i-th corner (−1000 ≤ xi, yi ≤ 1000). Coordinates of all corners are different, and adjacent walls of the room are not collinear. The corners are listed in clockwise order.
Output
Write four numbers x1, y1, x2, y2 to the output file, where (x1, y1) and (x2, y2) denote the spots where carpet centers should be placed. Coordinates must be precise up to 4 digits after the decimal point.
If there are multiple optimal placements available, return any of them. The input data guarantees that at least one solution exists.
Sample Input
| #1 | 5 2 -2 0 -5 3 0 8 7 3 5 0  | 
|---|---|
| #2 | 4 3 0 0 0 8 10 8 10 0  | 
Sample Output
| #1 | -2 3 3 2.5 | 
|---|---|
| #2 | 3 5 7 3 | 
Hint

Source
给你两个圆,半径相等,求放在一个凸多边形里两个圆不碰到边界的圆心。两个圆是可以重叠的。
半平面交,向内推进R,然后求组成多边形的最远的两个点即可。
/* ***********************************************
Author :kuangbin
Created Time :2013/8/18 15:52:28
File Name :F:\2013ACM练习\专题学习\计算几何\半平面交\POJ3384.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const double eps = 1e-;
const double PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps) return ;
if(x < ) return -;
else return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x; y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
};
struct Line
{
Point s,e;
double k;
Line(){}
Line(Point _s,Point _e)
{
s = _s; e = _e;
k = atan2(e.y - s.y,e.x - s.x);
}
Point operator &(const Line &b)const
{
Point res = s;
double t = ((s - b.s)^(b.s - b.e))/((s - e)^(b.s - b.e));
res.x += (e.x - s.x)*t;
res.y += (e.y - s.y)*t;
return res;
}
};
//半平面交,直线的左边代表有效区域
bool HPIcmp(Line a,Line b)
{
if(fabs(a.k - b.k) > eps)return a.k < b.k;
return ((a.s - b.s)^(b.e - b.s)) < ;
}
Line Q[];
void HPI(Line line[], int n, Point res[], int &resn)
{
int tot = n;
sort(line,line+n,HPIcmp);
tot = ;
for(int i = ;i < n;i++)
if(fabs(line[i].k - line[i-].k) > eps)
line[tot++] = line[i];
int head = , tail = ;
Q[] = line[];
Q[] = line[];
resn = ;
for(int i = ; i < tot; i++)
{
if(fabs((Q[tail].e-Q[tail].s)^(Q[tail-].e-Q[tail-].s)) < eps || fabs((Q[head].e-Q[head].s)^(Q[head+].e-Q[head+].s)) < eps)
return;
while(head < tail && (((Q[tail]&Q[tail-]) - line[i].s)^(line[i].e-line[i].s)) > eps)
tail--;
while(head < tail && (((Q[head]&Q[head+]) - line[i].s)^(line[i].e-line[i].s)) > eps)
head++;
Q[++tail] = line[i];
}
while(head < tail && (((Q[tail]&Q[tail-]) - Q[head].s)^(Q[head].e-Q[head].s)) > eps)
tail--;
while(head < tail && (((Q[head]&Q[head-]) - Q[tail].s)^(Q[tail].e-Q[tail].e)) > eps)
head++;
if(tail <= head + )return;
for(int i = head; i < tail; i++)
res[resn++] = Q[i]&Q[i+];
if(head < tail - )
res[resn++] = Q[head]&Q[tail];
}
Point p[];
Line line[];
//*两点间距离
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
void change(Point a,Point b,Point &c,Point &d,double p)//将线段ab往左移动距离p
{
double len = dist(a,b);
double dx = (a.y - b.y)*p/len;
double dy = (b.x - a.x)*p/len;
c.x = a.x + dx; c.y = a.y + dy;
d.x = b.x + dx; d.y = b.y + dy;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
double r;
while(scanf("%d%lf",&n,&r) == )
{
for(int i = ;i < n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
reverse(p,p+n);
for(int i = ;i < n;i++)
{
Point t1,t2;
change(p[i],p[(i+)%n],t1,t2,r);
line[i] = Line(t1,t2);
}
int resn;
HPI(line,n,p,resn);
int res1 = , res2 = ;
for(int i = ;i < resn;i++)
for(int j = i;j < resn;j++)
if(dist(p[i],p[j]) > dist(p[res1],p[res2]))
res1 = i, res2 = j;
printf("%.5f %.5f %.5f %.5f\n",p[res1].x,p[res1].y,p[res2].x,p[res2].y);
}
return ;
}
POJ 3384 Feng Shui (半平面交)的更多相关文章
- POJ 3384 Feng Shui 半平面交
		
题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...
 - poj 3384 Feng Shui (Half Plane Intersection)
		
3384 -- Feng Shui 构造半平面交,然后求凸包上最远点对. 这题的题意是给出一个凸多边形区域,要求在其中放置两个半径为r的圆(不能超出凸多边形区域),要求求出两个圆心,使得多边形中没有被 ...
 - POJ 3384 Feng Shui
		
http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最 ...
 - POJ 3384 Feng Shui(计算几何の半平面交+最远点对)
		
Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achie ...
 - POJ 3384 Feng Shui 凸包直径 + 半平面交
		
G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...
 - poj 3335 Rotating Scoreboard - 半平面交
		
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
 - POJ 3384	 Feng Shui --直线切平面
		
题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大. 解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠 ...
 - POJ 2540	 Hotter Colder --半平面交
		
题意: 一个(0,0)到(10,10)的矩形,目标点不定,从(0,0)开始走,如果走到新一点是"Hotter",那么意思是离目标点近了,如果是"Colder“,那么就是远 ...
 - POJ 3384 Feng Shui(半平面交向内推进求最远点对)
		
题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...
 
随机推荐
- https、socket、http协议
			
一.https https 其实是由两部分组成:http+ssl(Secure Sockets Layer 安全套接层)/tls(Transport Layer Security 继任者安全传输层), ...
 - 模块定义文件.def
			
一作用 DLL中导出函数的声明有两种方式:一种为在函数声明中加上__declspec(dllexport),这里不再举例说明:另外一种方式是采用模块定义(.def) 文件声明,.def文件为链接器提供 ...
 - 一键去除网页BOM属性【解决乱码,头部空白,问题】
			
几个常出现的问题: 1.网站打开空白 2.页面头部出现多余的空白 3.网站出现乱码,如“锘�” 解决方法可以是: 1.选用专业的编辑器,例如notepad++,sublime,editplus这样不会 ...
 - Mybatis的关联映射案例
			
主要是对之前学习的关联映射做一个案例,自己动手实践一下,可以理解的更好一点. 开发环境 开发工具:idea Java环境: jdk1.8.0_121 数据库:SQLServer 项目结构,里面包含了三 ...
 - jmeter-----查看结果树
			
在编写接口测试脚本的时候,需要进行调试和查看结果是否正常的情况,这个时候可以使用查看结果树组件进行. 查看结果树中展示了每一个取样器的结果.请求信息和响应信息,可以查看这些内容去分析脚本是否存在问题. ...
 - [实战]MVC5+EF6+MySql企业网盘实战(5)——页面模板
			
写在前面 上篇文章更新了网盘的登录界面,以及用户头像的等比例压缩功能.今天折腾一下页面的样式,将从网上找的一个模板套用在项目中. 系列文章 [EF]vs15+ef6+mysql code first方 ...
 - Docker Zero Deployment and Secrets (一)
			
在本节中,主要介绍在Docker swarm中如何不中断应用高可靠性的情况下更新服务和stack.这也叫做zero downtime deployment.还有就是swam如何管理密钥,保证容器之间的 ...
 - ftp缓存信息
			
using System.Collections.Generic; using NewTempo.Ftp; using System.IO; using NshowAdClient.NshowAdSe ...
 - ref:PHP反序列化漏洞成因及漏洞挖掘技巧与案例
			
ref:https://www.anquanke.com/post/id/84922 PHP反序列化漏洞成因及漏洞挖掘技巧与案例 一.序列化和反序列化 序列化和反序列化的目的是使得程序间传输对象会更加 ...
 - 初识 Fuzzing 工具 WinAFL
			
转:https://paper.seebug.org/323/ 初识 Fuzzing 工具 WinAFL 作者:xd0ol1(知道创宇404实验室) 0 引子 本文前两节将简要讨论 fuzzing 的 ...