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 < ...
随机推荐
- SGU 223.Little Kings
时间限制:0.25s 空间限制:4M 题意: 在 n*n(n≤10)的棋盘上放 k (k<=n*n)个国王(可攻击相邻的 8 个格子),求使它们无法互相攻击的方案数. Solution: 采用状 ...
- Linux下安装SVN服务(CentOS7下)
1. 安装 centos(我这里使用的是CentOS7)下yum命令即可方便的完成安装 测试安装是否成功: 2. 建立版本库 创建svn数据目录(subversion默认是把/var/svn作为数据根 ...
- 『重构--改善既有代码的设计』读书笔记----Introduce Local Extension
同Introduce Foreign Method一样,很多时候你不能修改编辑原始类,你需要为这些服务类增加一些额外的函数,但你没有这个权限或者入口.如果你只需要一个或者两个外加函数那么你可以放心的使 ...
- gzip命令
http://www.cnblogs.com/peida/archive/2012/12/06/2804323.html 减 少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时, ...
- underscorejs-sample学习
2.22 sample 2.22.1 语法: _.sample(list, [n]) 2.22.2 说明: 从list中产生一个随机样本.传参n后返回n个随机元素,各元素不重复. 2.22.3 代码示 ...
- Jqprint 轻量级页面打印插件
最近项目中需要在页面上添加一个打印的按钮,上网搜索了一下就发现了这个好用的超轻量插件,使用起来很方便 1.首先需要引入必须的js文件 <script language="javascr ...
- cocod2d-x 之 HelloWorld
cocos2d-x 2.2创建项目 进入cocos2d-x-2.2/tools/project-creator,运行命令 python create_project.py -project MyGam ...
- MAC——laravel环境
apache: 目录:etc/apache2 重启:sudo apachectl restart PHP: 把/etc/php.ini.default复制并重命名/ect/php.ini 打开Load ...
- gcc将多个静态库链接成一个静态库
参考:https://sourceware.org/binutils/docs/binutils/ar-scripts.html#ar-scripts makefile如下: ARSCRIPT=scr ...
- Node.js缓冲器
纯JavaScript是Unicode友好的,但对二进制数据不是很好.当与TCP流或文件系统打交道时,有必要处理字节流. Node提供缓冲器类,它提供实例来存储原始数据相似的一个整数数组,但对应于在V ...