关闭

[POJ3130]How I Mathematician Wonder What You Are!(半平面交)

535人阅读 评论(0) 收藏 举报
分类:

题目描述

传送门
题意:给出一个多边形,判断多边形是否有核

题解

所谓多边形的核,简单来说就是有个人站在这个点,那么这个多边形内的每一个点这个人都能看见(光沿直线传播)
也就是说对于多边形的每一条边的一个半平面求交,可以交出来一个凸壳,这个点集中的点都满足要求
附上pku的一个经典的图
这里写图片描述
这就是半平面交裸题了

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 1005

const double inf=1e6;
const double eps=1e-8;
int dcmp(double x)
{
    if (x<=eps&&x>=-eps) return 0;
    return (x>0)?1:-1;
}
struct Vector
{
    double x,y;
    Vector(double X=0,double Y=0)
    {
        x=X,y=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 a) {return Vector(A.x*a,A.y*a);}
bool operator == (Vector A,Vector B) {return dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)==0;}

int n,cnt,ncnt;
double x,y;
Point p[N],poly[N],npoly[N];

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));
}
bool insLS(Point A,Point B,Point C,Point D)
{
    Vector v=B-A,w=C-A,u=D-A;
    return dcmp(Cross(v,w))!=dcmp(Cross(v,u));
}
Point GLI(Point P,Vector v,Point Q,Vector w)
{
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}
void init()
{
    cnt=0;
    poly[++cnt]=Point(-inf,-inf);
    poly[++cnt]=Point(inf,-inf);
    poly[++cnt]=Point(inf,inf);
    poly[++cnt]=Point(-inf,inf);
}
void halfp(Point A,Point B)
{
    ncnt=0;
    Point C,D,ip;
    for (int i=1;i<=cnt;++i)
    {
        C=poly[i%cnt+1];
        D=poly[(i+1)%cnt+1];
        if (dcmp(Cross(B-A,C-A))>=0)
            npoly[++ncnt]=C;
        if (insLS(A,B,C,D))
        {
            ip=GLI(A,B-A,C,D-C);
            npoly[++ncnt]=ip;
        }
    }
    cnt=ncnt;
    for (int i=1;i<=cnt;++i)
        poly[i]=npoly[i];
}
int main()
{
    while (~scanf("%d",&n))
    {
        if (!n) break;
        for (int i=1;i<=n;++i)
        {
            scanf("%lf%lf",&x,&y);
            p[i]=Point(x,y);
        }
        init();
        for (int i=1;i<=n;++i)
            halfp(p[i%n+1],p[(i+1)%n+1]);
        if (cnt) puts("1");
        else puts("0");
    }
}
0
0
查看评论

LA 3616 How I Wonder What You Are! 三维几何 角度计算

题目地址:LA3616 直接O(nm)暴力枚举.. 代码:
  • jingqi814
  • jingqi814
  • 2014-05-17 04:02
  • 863

poj3130 How I Mathematician Wonder What You Are!【半平面交】

题目链接:http://poj.org/problem?id=3130 题意:给你一个多边形,让你判断是否是星星,星星的定义是如果有两个点ab属于多边形里面,那么线段ab也属于多边形里面 解析:仔细想想,如果是星星的话,那么也就相当于这个多边形存在核,所以直接套半平面交的模板,记住输入时逆时针的...
  • Richie_ll
  • Richie_ll
  • 2017-04-28 20:27
  • 293

poj3130How I Mathematician Wonder What You Are!+半平面交

半平面交
  • xtulollipop
  • xtulollipop
  • 2016-08-26 17:51
  • 314

POJ 3130: How I Mathematician Wonder What You Are! 半平面交

How I Mathematician Wonder What You Are!Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 4073 Accepted: 2194Des...
  • BlackJack_
  • BlackJack_
  • 2018-02-11 21:09
  • 51

poj_3130 How I Mathematician Wonder What You Are!(半平面交)

How I Mathematician Wonder What You Are! Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3674   Accepted: 198...
  • christry_stool
  • christry_stool
  • 2017-01-10 23:46
  • 105

poj 3130 How I Mathematician Wonder What You Are! (半平面交)

How I Mathematician Wonder What You Are! Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3668  ...
  • clover_hxy
  • clover_hxy
  • 2017-01-03 08:55
  • 157

POJ 3130 How I Mathematician Wonder What You Are!(半平面交)

和 POJ3335 几乎一模一样。。 //poj3130 #include #include #include #include #include #include #include #include #include #include #include #include ...
  • u013112097
  • u013112097
  • 2014-06-23 18:14
  • 259

POJ 3130 How I Mathematician Wonder What You Are! (计算几何+半平面交)

After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician uses a big astronomical telescope and lets his ...
  • baidu_35522092
  • baidu_35522092
  • 2017-09-12 15:40
  • 117

poj 3130 How I Mathematician Wonder What You Are!(半平面交)

How I Mathematician Wonder What You Are! Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2962  ...
  • u010527492
  • u010527492
  • 2013-11-28 13:19
  • 565

[poj 3130]How I Mathematician Wonder What You Are![半平面交][模板题]

题意: 判断多边形是否有核. 思路: 使用模板求多边形的核, 注意 input 中点的顺序. #include #define vector point const double INF = 1e18; struct point { double x,y; point(d...
  • zhangliang011258
  • zhangliang011258
  • 2013-08-28 11:20
  • 702
    个人资料
    • 访问:643041次
    • 积分:17905
    • 等级:
    • 排名:第630名
    • 原创:1151篇
    • 转载:7篇
    • 译文:0篇
    • 评论:190条
    联系方式
    QQ:1209628538 加好友请备注省份和ID
    E-mail:fiona_2000@126.com
    最新评论