POJ 3384 Feng Shui [半平面交]

Feng Shui

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5537   Accepted: 1663   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 nlines contain two integers xi and yi each — coordinates of the i-th corner (−1000 ≤ xiyi ≤ 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 x1y1x2y2 to the output file, where (x1y1) and (x2y2) 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.



题意:

在一个有 n 个点的凸包形状房间中,要放两个半径为 r 的圆形地毯,要求这两个地毯覆

盖地板的面积越大越好,求两个地毯圆心的位置。


先把凸包缩小r,就变成找圆心了,当然是最远点了,直接枚举点对就好了


变成逆时针直接reverse一下就好了

然而本题太恶心了.....不说了自己看discuss

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=205;
const double INF=1e3+5;
const double eps=1e-10;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();}
    return x*f;
}

inline int sgn(double x){
    if(abs(x)<eps) return 0;
    else return x<0?-1:1;
}

struct Vector{
    double x,y;
    Vector(double a=0,double b=0):x(a),y(b){}
    bool operator <(const Vector &a)const{
        return sgn(x-a.x)<0||(sgn(x-a.x)==0&&sgn(y-a.y)<0);
    }
    void print(){printf("%lf %lf\n",x,y);}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==0&&sgn(a.y-b.y)==0;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double Len(Vector a){return sqrt(Dot(a,a));}
Vector Normal(Vector a){
    return Vector(-a.y,a.x);//counterClockwise
}
struct Line{
    Point s,t;
    Line(){}
    Line(Point a,Point b):s(a),t(b){}
};
bool isLSI(Line l1,Line l2){
    Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
    return sgn(Cross(v,u))!=sgn(Cross(v,w));
}
Point LI(Line a,Line b){
    Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
    double t=Cross(v2,v)/Cross(v1,v2);
    return a.s+v1*t;
}

void iniPolygon(Point p[],int &n,double inf){
    n=0;
    p[++n]=Point(-inf,-inf);
    p[++n]=Point(inf,-inf);
    p[++n]=Point(inf,inf);
    p[++n]=Point(-inf,inf);
}
Point t[N];int tn;
void CutPolygon(Point p[],int &n,Point a,Point b){//get the left of a->b
    tn=0;
    Point c,d;
    for(int i=1;i<=n;i++){
        c=p[i],d=p[i%n+1];
        if(sgn(Cross(b-a,c-a))>=0) t[++tn]=c;
        if(isLSI(Line(a,b),Line(c,d)))
            t[++tn]=LI(Line(a,b),Line(c,d));
    }
    n=tn;for(int i=1;i<=n;i++) p[i]=t[i];
}

int n,r,m;
Point p[N],q[N];
Line L[N];
void ChangePolygon(Point p[],int n,double x){
    p[n+1]=p[1];
    for(int i=1;i<=n;i++){
        Vector v=Normal(p[i+1]-p[i])*x/Len(p[i+1]-p[i]);
        L[i]=Line(p[i]+v,p[i+1]+v);
    }
}

int main(int argc, const char * argv[]){
    while(scanf("%d%d",&n,&r)!=EOF){
        for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
        iniPolygon(q,m,INF);
        reverse(p+1,p+1+n);
        ChangePolygon(p,n,r);
        Point a,b;double mx=0;
        for(int i=1;i<=n;i++) CutPolygon(q,m,L[i].s,L[i].t);
        for(int i=1;i<=m;i++)
            for(int j=1;j<=m;j++) if(sgn(Len(q[j]-q[i])-mx)>=0){
                mx=Len(q[j]-q[i]);
                a=q[i];b=q[j];
            }
        if(a.x>b.x) swap(a,b);
        printf("%.4f %.4f %.4f %.4f\n",a.x,a.y,b.x,b.y);
    }
}
时间: 2024-10-09 06:12:47

POJ 3384 Feng Shui [半平面交]的相关文章

poj 3384 Feng Shui 半平面交的应用 求最多覆盖凸多边形的面积的两个圆 的圆心坐标

题目来源: http://poj.org/problem?id=3384 分析: 用半平面交将多边形的每条边一起向"内"推进R,得到新的多边形(半平面交),然后求多边形的最远两点. 代码如下: const double EPS = 1e-10; const int Max_N = 105 ; struct Point{ double x,y; Point(){} Point(double x, double y):x(x),y(y){} Point operator - (Point

POJ 3384 Feng Shui(半平面交向内推进求最远点对)

题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> using namespace std ; struct node { double x,y ; }p[110],temp[110],

POJ 3384 Feng Shui

http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最大距离的点对,就是圆心坐标. PS:最大长度的初始值要设置为负数,因为距离有可能退化到0,就像这组数据 4 1 0 0 2 0 2 2 0 2 #include<cstdio> #include<iostream> #include<cmath> #include<c

POJ 3384 Feng Shui --直线切平面

题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大. 解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠. 那么我们把所有边都向内推进r,那么形成的多边形,可知两个圆形地毯的中心就一定在这个多边形边界上,最优的情况下是在此新凸包的最远点对上. 初始多边形为(-1000,-1000)到(1000,1000)的矩形,那么我们可以模拟把每条边都推进,每次切出新的凸多边形,然后得出最后的凸多边形,然后n^2枚

POJ 2451 nlog(n)半平面交裸题。

前言       最近学习C#,不过好在当初考计算机二级学习过C++,刚上手没有对C#感到很恐惧.C#视频也看了几天 了,总感觉不总结一下心里没底,现在跟着我从头走进C#之旅吧.     C#是以后总面向对象的编程语言(OOP),C#是从C和C++派生出来的,主要用于开发可以运行在.NET平台 上的应用程序.随着.NET的发展,C#语言简单.现代.面向对象和类型安全显示了一定的优势.     下面我就介绍一些初学者不太理解的一些东西.   C#有以下突出的特点       (1)语法简洁.不允许

POJ 1279 Art Gallery 半平面交求多边形核

第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内,否则出现在左边,就可能会有交点,将交点求出加入. //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #inc

POJ 1474 Video Surveillance 半平面交求多边形是否有核

裸的半平面交求多边形是否有核. 多边形的核: 在多边形核上的点可以看到多边形的所有顶点,凸多边形的核显然就是多边形本身. 多边形的核是一个凸包,对多边形的所有边都做向着多边形的半平面交在判断一下是否构成凸包就可以了 一样的题目还有POJ3335 Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3438   Accepted: 1523 Description A friend of y

POJ 1279 Art Gallery 半平面交+求多边形核的面积

裸的:半平面交+求多边形核的面积 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5735   Accepted: 2419 Description The art galleries of the new and very futuristic building of the Center for Balkan Cooperation have the form of polygons (not

POJ 3335 Rotating Scoreboard 半平面交求多边形内核

题目大意:多边形求内核模板题 思路:半平面交,我用的是O(nlogn)的半平面交,但是有一个问题,就是当多边形内核是一个点的时候,半平面交所得到的答案是空集合,但是输出应该是yes,实在没有什么好的解决方法,最后只能把所有直线向右移动,然后在求内核.但是这样做eps的不同取值有的时候能A有的时候不能A.有没有什么好的解决方法啊!!!求解答啊!!! CODE: #include <cmath> #include <cstdio> #include <cstring> #i