博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3384Feng Shui
阅读量:5256 次
发布时间:2019-06-14

本文共 4167 字,大约阅读时间需要 13 分钟。

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 Input1

5 2
-2 0
-5 3
0 8
7 3
5 0

Sample Input2

4 3
0 0
0 8
10 8
10 0

Sample Output1

-2 3 3 2.5

Sample Output2

3 5 7 3

分析:

类似poj3525的思路
我们把每一条直线向内(向直线的右侧)平移r个单位,
那么两个圆的圆心必定在这个新凸多边形中,否则就会和原来的凸多边形的某条边相交
我们要最大化面积,
显然两个圆的圆心要相聚尽可能的远
所以查找一下新的凸多边形中距离最远的两个点即可
(有special judge)

这里写代码片#include
//顺时针#include
#include
#include
using namespace std;const int N=100001;const double eps=1e-8;struct node{ double x,y; node (double xx=0,double yy=0) { x=xx;y=yy; }};node po[N],p[N],q[N];int n,m;double a,b,c,r,PI=acos(-1.0);node operator +(const node &a,const node &b){ return node(a.x+b.x,a.y+b.y);}node operator -(const node &a,const node &b){ return node(a.x-b.x,a.y-b.y);}node operator *(const node &a,const double &b){ return node(a.x*b,a.y*b);}node operator /(const node &a,const double &b){ return node(a.x/b,a.y/b);}int dcmp(double x){ if (fabs(x)
0) return 1; else return -1;}double Cross(node x,node y){ return x.x*y.y-x.y*y.x;}double Dot(node x,node y){ return x.x*y.x+x.y*y.y;}double dis(node x,node y){ return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}void getline(node x,node y){ a=y.y-x.y; b=x.x-y.x; c=x.y*y.x-x.x*y.y;}node insert(node x,node y){ double u=a*x.x+b*x.y+c; double v=a*y.x+b*y.y+c; node ans; ans.x=(v*x.x+u*y.x)/(u+v); ans.y=(v*y.x+u*y.y)/(u+v); return ans;}void cut(){ int i,cnt=0; for (i=1;i<=m;i++) { if (a*p[i].x+b*p[i].y+c>=0) q[++cnt]=p[i]; else { if (a*p[i-1].x+b*p[i-1].y+c>0) q[++cnt]=insert(p[i],p[i-1]); if (a*p[i+1].x+b*p[i+1].y+c>0) q[++cnt]=insert(p[i],p[i+1]); } } for (i=1;i<=m;i++) p[i]=q[i]; p[0]=p[m]; p[m+1]=p[1]; m=cnt; return;}void pd(){ int i,j; double ans=0; node a,b; for (i=1;i
ans) { ans=t; a=p[i]; b=p[j]; } } } printf("%0.4lf %0.4lf %0.4lf %0.4lf",a.x,a.y,b.x,b.y); return;}void doit(){ int i; for (i=1;i<=n;i++) p[i]=po[i]; p[0]=p[n]; p[n+1]=p[1]; po[0]=po[n]; po[n+1]=po[1]; m=n; for (i=1;i<=n;i++) { getline(po[i],po[i+1]); c-=r*(sqrt(a*a+b*b)); //顺时针给点,直线向内平移 cut(); if (!m) break; } pd(); }int main(){ scanf("%d%d",&n,&r); for (int i=1;i<=n;i++) scanf("%lf%lf",&po[i].x,&po[i].y); doit(); return 0;}

转载于:https://www.cnblogs.com/wutongtong3117/p/7673498.html

你可能感兴趣的文章
使用&nbsp;SharedPreferences 分类: Andro...
查看>>
TLA+(待续...)
查看>>
题解: [GXOI/GZOI2019]与或和
查看>>
MacOS copy图标shell脚本
查看>>
国外常见互联网盈利创新模式
查看>>
Oracle-05
查看>>
linux grep 搜索查找
查看>>
Not enough free disk space on disk '/boot'(转载)
查看>>
android 签名
查看>>
vue项目中使用百度统计
查看>>
android:scaleType属性
查看>>
SuperEPC
查看>>
mysql-5.7 innodb 的并行任务调度详解
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
Js时间处理
查看>>
Java项目xml相关配置
查看>>
三维变换概述
查看>>
第三次作业
查看>>
vue route 跳转
查看>>