POJ 3384 Feng Shui(半平面交)
来源:互联网 发布:电脑椅子 家用知乎 编辑:程序博客网 时间:2024/05/09 11:39
转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526 by---cxlove
题目:给出一个凸多边形的房间,根据风水要求,把两个圆形地毯铺在房间里,不能折叠,不能切割,可以重叠。问最多能覆盖多大空间,输出两个地毯的圆心坐标。多组解输出其中一个
http://poj.org/problem?id=3384
题目保证至少可以放入一个圆,上一题中判断过在一个多边形内是否能放入一个半径为r的圆。
同样将多边形的边内移R之后,半平面交区域便是可以放入圆的可行区域。
题目要求覆盖的面积最大,也就是两个圆的半径相同,圆心越远,面积就越大。
在半平面交区域内找到最远点对便是题目要求的解。
然后就是注意精度啥啥啥的,听说这题很诡异,可是我1A了,好奇怪奇怪所以我也不知道哪有TRICK
#include<iostream>#include<fstream>#include<iomanip>#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>#include<set>#include<map>#include<queue>#include<stack>#include<string>#include<vector>#include<sstream>#include<cassert>#define LL long long#define eps 1e-5#define inf 1<<30using namespace std;struct Point{ double x,y;}p[1505],tp[1505],q[1505];double dist(Point p1,Point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}//叉积double xmul(Point p0,Point p1,Point p2){ return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);}//通过两点,确定直线方程double Get_equation(Point p1,Point p2,double &a,double &b,double &c){ a=p2.y-p1.y; b=p1.x-p2.x; c=p2.x*p1.y-p1.x*p2.y;}//求交点Point Intersection(Point p1,Point p2,double a,double b,double c){ double u=fabs(a*p1.x+b*p1.y+c); double v=fabs(a*p2.x+b*p2.y+c); Point t; t.x=(p1.x*v+p2.x*u)/(u+v);t.y=(p1.y*v+p2.y*u)/(u+v); return t;}//求面积,正为顺时针,和叉积写法有关double Get_area(Point p[],int n){ double area=0; for(int i=2;i<n;i++) area+=xmul(p[1],p[i],p[i+1]); return -area/2.0;}//改变顺序double Change_dir(Point p[],int n){ for(int i=1;i<=n/2;i++) swap(p[i],p[n+1-i]);}//加入一条边,切割void Cut(double a,double b,double c,Point p[],int &cnt){ int tmp=0; for(int i=1;i<=cnt;i++){ //当前点就在右侧 if(a*p[i].x+b*p[i].y+c>-eps) tp[++tmp]=p[i]; else{ //前一个点在右侧,产生交点 if(a*p[i-1].x+b*p[i-1].y+c>eps) tp[++tmp]=Intersection(p[i-1],p[i],a,b,c); //同理 if(a*p[i+1].x+b*p[i+1].y+c>eps) tp[++tmp]=Intersection(p[i],p[i+1],a,b,c); } } for(int i=1;i<=tmp;i++) p[i]=tp[i]; p[0]=p[tmp];p[tmp+1]=p[1]; cnt=tmp;}int slove(Point q[],int n,double r){ //默认顺时针,通过面积判断一下 if(Get_area(q,n)<eps) Change_dir(q,n); q[0]=q[n];q[n+1]=q[1]; //原来的点要备份一遍,查了好久 for(int i=0;i<=n+1;i++) p[i]=q[i]; int cnt=n; for(int i=1;i<=n;i++){ double a,b,c; Point p1,p2,p3; p1.y=q[i].x-q[i+1].x;p1.x=q[i+1].y-q[i].y; double k=r/sqrt(p1.x*p1.x+p1.y*p1.y); p1.x=k*p1.x;p1.y=p1.y*k; p2.x=p1.x+q[i].x;p2.y=p1.y+q[i].y; p3.x=p1.x+q[i+1].x;p3.y=p1.y+q[i+1].y; Get_equation(p2,p3,a,b,c); Cut(a,b,c,p,cnt); } double maxdist=0; Point p1,p2; for(int i=1;i<=cnt;i++) for(int j=1;j<=cnt;j++){ double d=dist(p[i],p[j]); if(d+eps>maxdist){ maxdist=d; p1=p[i]; p2=p[j]; } } printf("%.4f %.4f %.4f %.4f\n",p1.x,p1.y,p2.x,p2.y);}int main(){ int n,r; while( scanf("%d%d",&n,&r)!=EOF){ for(int i=1;i<=n;i++) scanf("%lf%lf",&q[i].x,&q[i].y); slove(q,n,r); } return 0;}
- POJ 3384 Feng Shui(半平面交)
- POJ 3384 Feng Shui 半平面交
- POJ 3384 Feng Shui 半平面交
- POJ 3384 Feng Shui(半平面交)
- 【半平面交】 POJ 3384 Feng Shui
- POJ 3384 Feng Shui 半平面交
- [半平面交] poj 3384 Feng Shui
- POJ 3384 Feng Shui(半平面交)
- Poj 3384 Feng Shui (半平面求交应用)
- poj 3384 Feng Shui(半平面交)
- POJ 3384 Feng Shui 凸包直径 + 半平面交
- poj 3384 Feng Shui(半平面交推进多边形)
- poj 3384 Feng Shui (半平面交)
- poj 3384 Feng Shui(半平面交)
- POJ 3384 Feng Shui (计算几何+半平面交)
- POJ 3384 Feng Shui (半平面交)
- poj 3384 Feng Shui(内推进半平面交+最远点对)
- POJ 3384 Feng Shui (半平面交求多边形内两个圆最大面积)
- 判断字符串是否包含,移位的方式去做做
- UVA113密码学的力量
- 二进制日志学习总结
- UVA120-煎饼摊
- objcopy、 objdump作用 、(bin文件和ELF文件区别)
- POJ 3384 Feng Shui(半平面交)
- C 对于C语言可移植性的思考
- wince6 两个应用程序进程间通信 OnCopyData
- C++程序(1),最好在虚拟机上运行
- UVA123-快速查找
- SharedPreferences用法
- GNU汇编生成二进制bin文件
- 黑马程序员——事件监听机制
- shell中for和while区别