POJ 3384 Feng Shui 凸包直径 + 半平面交
G++一直没有过了 换成 C++果断A掉了。。。It's time to bet RP.
题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标。
思路:将多边形的边向里平移圆的的半径R,然后求新多边形的距离最长的两个点。
平移多少废了一点脑筋,其他的就都是现成的模板了。
这个是平移的函数,自己想得,不知道还有没有更简便的。左右平移只需要改一下 向量 V
void Panning_Edge(P &a1,P &a2,double dis)
{
//向v的右侧平移
P v = {a2.y-a1.y,a1.x-a2.x}; double t = dis/Cal_Point_Dis(a1,a2); a1.x = a1.x+v.x * t;
a1.y = a1.y+v.y * t; a2.x = a2.x+v.x*t;
a2.y = a2.y+v.y*t;
}
PS:好吧,我承认自己没想出,然后翻了别人的题解。。。。这个内推边真的用的好巧哇
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string> #define LL long long
#define EPS (1e-9)
#define Right 1;
#define Left -1; using namespace std; struct P
{
double x,y;
} p[55],tp[2510],cp[2510]; double X_Mul(P a1,P a2,P b1,P b2)
{
P v1 = {a2.x-a1.x,a2.y-a1.y},v2 = {b2.x-b1.x,b2.y-b1.y};
return v1.x*v2.y - v1.y*v2.x;
} P Cal_Cross_Position(P a1,P a2,P b1,P b2)
{
double t = fabs(X_Mul(a1,a2,a1,b1))/fabs(X_Mul(a1,a2,b2,b1));
P p = {b1.x + (b2.x-b1.x)*t,b1.y + (b2.y-b1.y)*t};
return p;
} double Cal_Point_Dis(P a1,P a2)
{
return sqrt((a2.x-a1.x)*(a2.x-a1.x) + (a2.y-a1.y)*(a2.y-a1.y));
} void Panning_Edge(P &a1,P &a2,double dis)
{
//向v的右侧平移
P v = {a2.y-a1.y,a1.x-a2.x}; double t = dis/Cal_Point_Dis(a1,a2); a1.x = a1.x+v.x * t;
a1.y = a1.y+v.y * t; a2.x = a2.x+v.x*t;
a2.y = a2.y+v.y*t;
} int Cut_Polygon(P a1,P a2,P *tp,int n,P *cp,double rad)
{
Panning_Edge(a1,a2,rad); double xm1,xm2;
int i ,top = 0;
for(i = 0;i < n; ++i)
{
xm1 = X_Mul(a1,a2,a1,tp[i]),xm2 = X_Mul(a1,a2,a1,tp[i+1]);
if(xm1 < EPS && xm2 < EPS)
{
cp[top++] = tp[i];
}
else if(xm1 < EPS || xm2 < EPS)
{
if(xm1 < EPS)
{
cp[top++] = tp[i];
}
cp[top++] = Cal_Cross_Position(a1,a2,tp[i],tp[i+1]);
}
}
cp[top] = cp[0];
return top;
} void Cal_Center_Position(P *tp,P *cp,P *p,int n,double rad)
{
int i,j,top; for(i = 0;i <= n; ++i)
{
tp[i] = p[i];
} for(top = n,i = 0;i < n; ++i)
{
top = Cut_Polygon(p[i],p[i+1],tp,top,cp,rad);
for(j = 0;j <= top; ++j)
{
tp[j] = cp[j];
}
//点集内有重点
} //求凸包的直径 鉴于点集不是很大 也懒得写旋转卡壳了 double TempDis,MaxDis = -1;
int s1,s2; for(i = 0;i <= top; ++i)
{
for(j = 0;j <= top; ++j)
{
TempDis = Cal_Point_Dis(tp[i],tp[j]);
if(MaxDis < TempDis)
{
MaxDis = TempDis,s1 = i,s2 = j;
}
}
} //最终答案
printf("%.4lf %.4lf %.4lf %.4lf\n",tp[s1].x,tp[s1].y,tp[s2].x,tp[s2].y); } int main()
{
int i,n;
double rad;
while(scanf("%d %lf",&n,&rad) != EOF)
{
for(i = 0; i < n; ++i)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
} p[n] = p[0]; Cal_Center_Position(tp,cp,p,n,rad);
}
return 0;
}
POJ 3384 Feng Shui 凸包直径 + 半平面交的更多相关文章
- POJ 3384 Feng Shui 半平面交
题目大意:一个人很信"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 --直线切平面
题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大. 解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠 ...
- POJ 3384 Feng Shui(半平面交向内推进求最远点对)
题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...
- 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 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...
随机推荐
- 我的Python成长之路---第一天---Python基础(4)---2015年12月26日(雾霾)
五.数据运算与数据运算符 1.算术运算符 算术运算符 运算符 描述 示例 + 加法 >>> 14 - 5 9 - 减法 >>> 14 - 5 9 * 乘法 &g ...
- Linux C网络编程学习笔记
Linux C网络编程总结报告 一.Linux C 网络编程知识介绍: 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户端:(client) 在网络程序中, ...
- Hash table in PowerShell
hashtable is easy to create, access and manipulate. we simply use $hashTable = @{} to create an empt ...
- Webx pull service
1.概述 pull service的功能是将对象置入模板中.被pull service放到模板中的对象,不需要应用程序的干预即可直接使用.如果模板没有用到某个对象,则不会产生创建该对象的开销.看起来, ...
- 转: css3动画简介以及动画库animate.css的使用
~~~ transition animation 和 animate.css 在这个年代,你要是不懂一点点css3的知识,你都不好意思说你是个美工.美你妹啊,请叫我前端工程师好不好.呃..好吧,攻城 ...
- Correlation rule tuning
Lots of organizations are deploying SIEM systems either to do their due diligence or because it’s pa ...
- VS2012 EF5 连接oracle11.2
1.安装ODAC 11.2 Release 5 and Oracle Developer Tools for Visual Studio (11.2.0.3.20). 注:支持VS2010和VS201 ...
- lwp 模拟行锁堵塞 前端超时
jrhmpt01:/root/async# cat a2.pl use LWP::UserAgent; use utf8; use DBI; use POSIX; use HTTP::Date qw( ...
- windows上放弃使用PyGTK
windows上放弃使用PyGTK - riag的专栏 - 博客频道 - CSDN.NET windows上放弃使用PyGTK 分类: python 2010-03-31 16:47 1054人阅读 ...
- STM32关于优先级设定的理解 NVIC_SetPriority()
Systick模块初始化配置函数(Systick_config)中设定模块中断优先级的函数为: NVIC_SetPriority((SysTick_IRQn, (1<<__NVIC_PRI ...