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 < ...
随机推荐
- system.getProperties()
Properties props=System.getProperties(); //系统属性 System.out.println("Java的运行环境版本:"+prop ...
- ie8 background css没有显示?——都是空格惹的祸
ie8 background css没有显示?——都是空格惹的祸
- QTP插入Output Value和插入CheckPoint,注意点
1. 必须打开程序才能进行Output value和CheckPoint的插入. 2. 也有可能是对象获取不到,从新加载对象库. 提示如下图:
- 使用Raphael 画图(一) 基本图形 (javascript)
Raphael是什么? Raphael 是一个用于在网页中绘制矢量图形的 Javascript 库.它使用 SVG W3C 推荐标准和 VML 作为创建图形的基础,你可以通过 JavaScript 操 ...
- STM32学习笔记——DMA控制器(向原子哥学习)
一.DMA简介 DMA,全称为:Direct Memory Access,即直接存储器访问,DMA 用来提供在外设和存储器之间或者存储器和存储器之间的高速数据传输.当 CPU 初始化这个传输动作,传输 ...
- Linux学习2
第三讲Linux常用命令04 压缩:gzip: 1.只能压缩文件,不能压缩目录 2.不保留源文件 解压缩:gunzip gzip -d ------------------------------ ...
- hdu不要62
Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来, ...
- 老oj2146 && Pku2135 Farm Tour
Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprise ...
- 一篇旧文章,结合汇编探索this指针
//VC6.0下成功编译 #include <iostream.h> class X{ public: void foo(int b,int c){ this->a=b*c; cou ...
- Inna and Binary Logic
Codeforces Round #234 (Div. 2) E:http://codeforces.com/problemset/problem/400/E 题意:给你n个数,然后每相邻的两个数可以 ...