POJ 3384 Feng Shui 半平面交
题目大意:一个人很信“Feng Shui”,他要在房间里放两个圆形的地毯。
这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面。求这两个地毯可以覆盖的最大范围。并输出这两个地毯的圆心。
思路:我们当然希望这两个圆形的地毯离得尽量的远,这种话两个圆之间的重叠区域就会越小,总的覆盖区域就越大。
那我们就先把每一条边向内推进地毯的半径的距离,然后求一次半平面交,这个求出的半平面的交集就是圆心能够取得地方,然后就暴力求出这当中的最远点对即可了。
CODE:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 110
#define EPS 1e-10
#define DCMP(a) (fabs(a) < EPS)
using namespace std; struct Point{
double x,y; Point(double _ = .0,double __ = .0):x(_),y(__) {}
Point operator +(const Point &a)const {
return Point(x + a.x,y + a.y);
}
Point operator -(const Point &a)const {
return Point(x - a.x,y - a.y);
}
Point operator *(double a)const {
return Point(x * a,y * a);
}
void Read() {
scanf("%lf%lf",&x,&y);
}
}point[MAX],p[MAX],polygen[MAX];
struct Line{
Point p,v;
double alpha; Line(Point _,Point __):p(_),v(__) {
alpha = atan2(v.y,v.x);
}
Line() {}
bool operator <(const Line &a)const {
return alpha < a.alpha;
}
}line[MAX],q[MAX]; int points,lines;
double adjustment; inline double Cross(const Point &a,const Point &b)
{
return a.x * b.y - a.y * b.x;
} inline double Calc(const Point &a,const Point &b)
{
return sqrt((a.x - b.x) * (a.x - b.x) +
(a.y - b.y) * (a.y - b.y));
} inline bool OnLeft(const Line &l,const Point &p)
{
return Cross(l.v,p - l.p) >= 0;
} inline void MakeLine(const Point &a,const Point &b)
{
Point p = a,v = b - a;
Point _v(-v.y / Calc(a,b),v.x / Calc(a,b));
p = _v * adjustment + p;
line[++lines] = Line(p,v);
} inline Point GetIntersection(const Line &a,const Line &b)
{
Point u = a.p - b.p;
double temp = Cross(b.v,u) / Cross(a.v,b.v);
return a.p + a.v * temp;
} int HalfPlaneIntersection()
{
int front = 1,tail = 1;
q[tail] = line[1];
for(int i = 2;i <= lines; ++i) {
while(front < tail && !OnLeft(line[i],p[tail - 1])) --tail;
while(front < tail && !OnLeft(line[i],p[front])) ++front;
if(DCMP(Cross(line[i].v,q[tail].v)))
q[tail] = OnLeft(line[i],q[tail].p) ? q[tail]:line[i];
else q[++tail] = line[i];
if(front < tail) p[tail - 1] = GetIntersection(q[tail],q[tail - 1]);
}
while(front < tail && !OnLeft(q[front],p[tail - 1])) --tail;
p[tail] = GetIntersection(q[tail],q[front]);
int re = 0;
for(int i = front;i <= tail; ++i)
polygen[++re] = p[i];
return re;
} pair<Point,Point> GetFarest(int cnt)
{
double max_length = -1.0;
pair<Point,Point> re;
for(int i = 1;i <= cnt; ++i)
for(int j = i;j <= cnt; ++j)
if(Calc(polygen[i],polygen[j]) > max_length) {
max_length = Calc(polygen[i],polygen[j]);
re.first = polygen[i];
re.second = polygen[j];
}
return re;
} int main()
{
cin >> points >> adjustment;
for(int i = 1;i <= points; ++i)
point[i].Read();
for(int i = points;i > 1; --i)
MakeLine(point[i],point[i - 1]);
MakeLine(point[1],point[points]);
sort(line + 1,line + lines + 1);
int cnt = HalfPlaneIntersection();
pair<Point,Point> re = GetFarest(cnt);
printf("%.6lf %.6lf %.6lf %.6lf\n",re.first.x,re.first.y,re.second.x,re.second.y);
return 0;
}
POJ 3384 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 (半平面交)
Feng Shui Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3743 Accepted: 1150 Speci ...
- 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 < ...
随机推荐
- swfupload上传文件问题
如果你的框架用到了struts2的话 可能会造成request冲突 那么解决的办法就是把该request排除出去 不让struts2拦截
- 防止iframe嵌套
如果你哪个页面不想被嵌套 下面js代码可以解决(我的是火狐) 慎用 <script type="text/javascript"> window.on ...
- CentOS 6.5 IP 设置
DEVICE=eth0TYPE=EthernetUUID=7d6d54e0-054d-472b-8cc1-080f16ef36c1ONBOOT=yesNM_CONTROLLED=yesBOOTPROT ...
- Javascript参数传递中值和引用的一种理解
值(value)和引用(reference)是各种编程语言老生常谈的话题,js也不例外. 我将剖析一个例子的实际运行过程,跟大家分享我对js参数传递中的值和引用的理解. 参考官网数据类型的两种分类,本 ...
- php——composer 1、安装使用
Composer 是PHP中用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer会帮你安装这些依赖的库文件. 系统要求 运 ...
- STM32自带的bool型变量
这些标着位会让你的程序使用起来更方便. First you need to include "STM32f10x_type.h" /*布尔型变量*/typedef enum{FAL ...
- 转:Java架构师与开发者提高效率的10个工具
原文来自于:http://www.importnew.com/14624.html Java受到全球百万计开发者的追捧,已经演变为一门出色的编程语言.最终,这门语言随着技术的变化,不断的被改善以迎合变 ...
- 应用hexo(rss插件)
使用RSS插件,来生成rss信息. 装载RSS插件 hexo根目录下进入git命令台 npm install hexo-generator-sitemap 启用RSS插件 hexo根目录下的 _con ...
- Js Framework
http://www.mhtml5.com/2012/06/5119.html http://www.mhtml5.com/2012/06/5118.html http://cubiq.org/isc ...
- unity NGUI点击消息不传入到场景中去
unity NGUI点击消息不传入到场景中去 1.今天遇到的问题是点击NGUI的按钮,场景中也相应了这个消息 解决的办法是在场景中需要互动的时候,也就是在update中进行判断 是否是点击了NGUI按 ...