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 < ...
随机推荐
- smarty 的学习----ubuntu下初步配置
转自:http://blog.csdn.net/ma332567575/article/details/7904124 首先去www.smarty.net下载最新版的Smarty 把下载后的压缩包在网 ...
- js 中的流程控制-条件语句
条件语句: if(exp)执行一句代码 <script> var x = 1 ; if(x == 1 ) //当if判断语句结果是true 或者 false 当判断结果等于true的时候, ...
- PHP android ios相互兼容的AES加密算法
APP项目用户密码传输一直没有用HTTPS,考虑到用户的隐私暂时先用AES对密码加密,以后也可以用于手机端与服务端加密交互. PHP的免费版phpAES项目,手机端解码各种不对. 好不容易找了PHP ...
- PHP面向对象(OOP):克隆对象__clone()方法
有的时候我们需要在一个项目里面,使用两个或多个一样的对象,如果你使用“new”关键字重新创建对象的话,再赋值上相同的属性,这样做比较烦琐而且也容易出错,所以要根据一个对象完全克隆出一个一模一样的对象, ...
- TatukGIS - GisDefs - CreateMSJET 函数
函数名称 CreateMSJET 所在单元 GisDefs 函数原型 function CreateMSJET(const _path: String): String; ...
- BAE 环境下配置 struts2 + spring + hibernate(SSH)(二)struts2
在myeclipse下开发的 应用但是 放到BAE下就出现了问题,虽然显示发布成功,但是访问的时候就会出现503 Service Unavailable 错误.通过调整 web.xml 发现纯Serv ...
- 操作Json
C#可以像Javascript一样操作Json 阅读目录 Json的简介 Json的优点 传统操作Json 简易操作Json Json的简介 JSON(JavaScript Object Notati ...
- 关于org.openqa.selenium.ElementNotVisibleException
最近在使用Selenium,编写最简单的百度search脚本,结果使用name来定位元素抛出了如下exception: 在定位百度的输入框,使用By.name()定位失败,但是使用By.id()和By ...
- Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)
Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一) 题记: 我们在使用SolrCloud中会经常发现会有备份的shard出现状态Recoverying,这就表明Solr ...
- Automated Telephone Exchange
Time Limit: 3000MS Memory limit: 65536K 题目描述In St Petersburg phone numbers are formatted as “XXX–XX– ...