poj 3384 半平面交
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 5183 | Accepted: 1548 | 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 |
/*
poj 3384 给你一个多边形,然后往里面放两个圆,问能够占的最大面积.
即相当于在能够放下两个圆的情况下使圆形离得尽可能的远. 如果将多边形的每条边往里面平移半径的长度R.那么剩下的多边形就是圆心的取点范围
然后在这个基础上枚举点即可. 主要是通过剩下的这些线段构成一个新的多边形,然后枚举它的顶点即可。
但是平移后的多边形的边的长度莫有变诶,所以可以看成多条直线围成的多边形。
那么就成了半平面交问题(即给你直线和图形在这条直线的哪一边,然后构成的多边形) hhh-2016-05-17 19:55:56
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
using namespace std;
const int maxn = 300;
const double PI = 3.1415926;
const double eps = 1e-10; int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0)
return -1;
else
return 1;
} 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,t;
double k;
Line() {}
Line(Point _s,Point _t)
{
s = _s;
t = _t;
k = atan2(t.y-s.y,t.x-s.x);
}
Point operator &(const Line &b) const
{
Point res = s;
double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
res.x += (t.x-s.x)*ta;
res.y += (t.y-s.y)*ta;
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.t-b.s)) < 0;
}
Line li[maxn]; double CalArea(Point p[],int n)
{
double ans = 0;
for(int i = 0; i < n; i++)
{
ans += (p[i]^p[(i+1)%n])/2;
}
return ans;
} double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
} void HPI(Line line[],int n,Point res[],int &resn)
{
int tot =n;
sort(line,line+n,HPIcmp);
tot = 1;
for(int i = 1; i < n; i++)
{
if(fabs(line[i].k - line[i-1].k) > eps)
line[tot++] = line[i];
}
int head = 0,tail = 1;
li[0] = line[0];
li[1] = line[1];
resn = 0;
for(int i = 2; i < tot; i++)
{
if(fabs((li[tail].t-li[tail].s)^(li[tail-1].t-li[tail-1].s)) < eps||
fabs((li[head].t-li[head].s)^(li[head+1].t-li[head+1].s)) < eps)
return;
while(head < tail && (((li[tail] & li[tail-1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
tail--;
while(head < tail && (((li[head] & li[head+1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
head++;
li[++tail] = line[i];
}
while(head < tail && (((li[tail] & li[tail-1]) - li[head].s) ^ (li[head].t-li[head].s)) > eps)
tail--;
while(head < tail && (((li[head] & li[head-1]) - li[tail].s) ^ (li[tail].t-li[tail].t)) > eps)
head++;
if(tail <= head+1)
return;
for(int i = head; i < tail; i++)
res[resn++] = li[i]&li[i+1];
if(head < tail-1)
res[resn++] = li[head]&li[tail];
double Mans = -1;
int ansi,ansj;
for(int i = 0; i < resn; i++)
{
for(int j = 0; j < resn; j++)
if( sgn(dist(res[i],res[j])-Mans) >= 0)
{
Mans = dist(res[i],res[j]) ;
ansi = i,ansj = j;
}
}
printf("%.4f %.4f %.4f %.4f\n",res[ansi].x,res[ansi].y,res[ansj].x,res[ansj].y);
}
Point p0;
Point lis[maxn];
Line line[maxn];
bool cmp(Point a,Point b)
{
double t = (a-p0)^(b-p0);
if(sgn(t) > 0)return true;
else if(sgn(t) == 0 && sgn(dist(a,lis[0])-dist(b,lis[0])) <= 0)
return true;
else
return false;
} Point ta,tb;
Point tans[maxn];
void fin(Point a,Point b,double mid)
{
double len = dist(a,b);
double dx = (a.y-b.y)*mid/len;
double dy = (b.x-a.x)*mid/len;
ta.x = a.x+dx,ta.y = a.y+dy;
tb.x = b.x+dx,tb.y = b.y+dy;
} int main()
{
//freopen("in.txt","r",stdin);
int n;
double r;
while(scanf("%d%lf",&n,&r)!= EOF)
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&lis[i].x,&lis[i].y);
}
reverse(lis,lis+n);
for(int i = 0; i < n; i++)
{
fin(lis[i],lis[(i+1)%n],r);
line[i] = Line(ta,tb);
}
int resn;
HPI(line,n,tans,resn);
}
return 0;
}
poj 3384 半平面交的更多相关文章
- POJ 3384 Feng Shui 半平面交
题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...
- 【kuangbin专题】计算几何_半平面交
1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...
- 【BZOJ-4515】游戏 李超线段树 + 树链剖分 + 半平面交
4515: [Sdoi2016]游戏 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 304 Solved: 129[Submit][Status][ ...
- poj3335 半平面交
题意:给出一多边形.判断多边形是否存在一点,使得多边形边界上的所有点都能看见该点. sol:在纸上随手画画就可以找出规律:按逆时针顺序连接所有点.然后找出这些line的半平面交. 题中给出的点已经按顺 ...
- POJ3525 半平面交
题意:求某凸多边形内部离边界最远的点到边界的距离 首先介绍半平面.半平面交的概念: 半平面:对于一条有向直线,它的方向的左手侧就是它所划定的半平面范围.如图所示: 半平面交:多个半平面的交集.有点类似 ...
- bzoj2618[Cqoi2006]凸多边形 半平面交
这是一道半平面交的裸题,第一次写半平面交,就说一说我对半平面交的理解吧. 所谓半平面交,就是求一大堆二元一次不等式的交集,而每个二元一次不等式的解集都可以看成是在一条直线的上方或下方,联系直线的标准方 ...
- BZOJ2618[Cqoi2006]凸多边形——半平面交
题目描述 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. 输入 第一行有一个整数n,表示凸多边形的个数,以下依次描述各个多边形.第 ...
- 洛谷P3222 [HNOI2012]射箭(计算几何,半平面交,双端队列)
洛谷题目传送门 设抛物线方程为\(y=ax^2+bx(a<0,b>0)\),我们想要求出一组\(a,b\)使得它尽可能满足更多的要求.这个显然可以二分答案. 如何check当前的\(mid ...
随机推荐
- 如何使用ILAsm与ILDasm修改.Net exe(dll)文件
一.背景 最近项目组新上项目,交付的时间比较急迫,原本好的分支管理习惯没有遵守好,于是出现下面状况: 多个小伙伴在不同的分支上开发. 原本QA环境也存在一个阻碍性的bug A 一位同事在QA环境发布了 ...
- var、let、const区别
1.let不存在变量提升,必须升明后才可用. 'use strict'; (function(){ console.log(varTest); console.log(letTest); var va ...
- vue初尝试--组件
github代码同步网址 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添 ...
- java图片处理开源框架
java图片处理开源框架 以前一直不明白,java开源框架什么意思,搜集资料得出以下结论 其实java框架可以理解为一个工具或者一个插件,将一个公用的.常用的技术封装起来,处理一些基础的.繁琐的问题. ...
- Mybatis入门程序
作为一个java的学习者,我相信JDBC是大家最早接触也是入门级别的数据库连接方式,所以我们先来回忆一下JDBC作为一种用于执行SQL语句的Java API是如何工作的.下面的一段代码就是最基本的JD ...
- Mego开发文档 - 索引
Mego 开发文档 Mego 快速概述 主要特性 获取Mego 使用流程 模型 查询 保存数据 入门 Mego 快速开始 创建项目 安装Nuget包 创建连接字符串 创建模型及数据上下文(添加引用) ...
- maven常见问题处理(3-4)配置代理服务器
有的公司基于安全因素考虑,要求员工使用通过安全认证的代理访问因特网. 这时就需要为Maven配置HTTP代理. 在目录~/.m2/setting.xml文件中编辑如下(如果没有该文件,则复制$M2_H ...
- 用Jmeter实现mysql数据库的增删查改
主要是参考虫师的“使用JMeter创建数据库(Mysql)测试”. 1.打开Jmeter,点击测试计划 链接:https://pan.baidu.com/s/1ZtaZ6IC_0DRjSlXkjslY ...
- VMware虚拟机安装
学习Linux系统最好的方式就是在自己的虚拟机上安装Linux:接下来就给大家简单介绍一下VMware虚拟机的安装以及Linux的安装:VMware虚拟机只是为了更好的学习Linux: ...
- python——常用模块2
python--常用模块2 1 logging模块 1.1 函数式简单配置 import logging logging.debug("debug message") loggin ...