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

和POJ3335一样,只不过这题是逆时针

#include <iostream>
#include <cstdio>
#include <cmath>
#define eps 1e-18
using namespace std;

const int MAXN = 105;
double a, b, c;
int n, cnt;

struct Point
{
    double x, y;
}point[MAXN], p[MAXN], tp[MAXN];

void Get_equation(Point p1, Point p2)
{
    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 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;
}

void Cut()
{
    int tmp = 0;
    for(int i=1; i<=cnt; i++)
    {
        //顺时针是>-eps和>eps,逆时针是<eps和<-eps
        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]);
            if(a * p[i+1].x + b * p[i+1].y + c < -eps)
                tp[++tmp] = Intersection(p[i], p[i+1]);
        }
    }
    for(int i=1; i<=tmp; i++)
        p[i] = tp[i];
    p[0] = p[tmp];
    p[tmp+1] = p[1];
    cnt = tmp;
}

void solve()
{
    for(int i=1; i<=n; i++)
        p[i] = point[i];
    point[n+1] = point[1];
    p[0] = p[n];
    p[n+1] = p[1];
    cnt = n;
    for(int i=1; i<=n; i++)
    {
        Get_equation(point[i], point[i+1]);
        Cut();
    }
}

int main()
{
    while(~scanf("%d", &n) && n)
    {
        for(int i=1; i<=n; i++)
            scanf("%lf%lf", &point[i].x, &point[i].y);
        solve();
        puts(cnt > 0? "1" : "0");
    }
    return 0;
}
时间: 2024-08-09 10:35:28

POJ 3130 How I Mathematician Wonder What You Are! 半平面交的相关文章

POJ 3525 Most Distant Point from the Sea 二分+半平面交

题目大意:给出一个岛的海岸线的轮廓,求这个岛上的所有点到海岸的最长距离是多少. 思路:求多边形内切圆的问题要用二分+半平面交解决.二分半径的长度,然后将所有的边向左侧移动这个二分的长度,然后利用半平面交来判断是否能够满足条件.如果满足条件就提高下界,否则减小上界. 我的移动的方法是这样的,首先每条边都要用点向量式来表示,就是边上任意一点和这条边的方向向量.这样做以后的操作会方便很多.然后将每个直线的向左的法向量求出来(比如l的向量是v(x,y),那么它向左侧的法向量是(-y,x)),然后将法向量

poj 3130 How I Mathematician Wonder What You Are!

How I Mathematician Wonder What You Are! Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3568   Accepted: 1906 Description After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician uses a big

POJ 2451 Uyuw&#39;s Concert(半平面交nlgn)

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <cstring> #include <cmath> #include <stack> #include <queue> #include <vector> #include <

How I Mathematician Wonder What You Are! POJ - 3130(半平面交,多边形内核)

How I Mathematician Wonder What You Are! POJ - 3130 题意:判断多边形是否有内核 思路:半平面交题,逆时针存入 1 // 2 // Created by HJYL on 2020/2/6. 3 // 4 #include<iostream> 5 #include<stdio.h> 6 #include<algorithm> 7 #include<math.h> 8 using namespace std; 9

POJ 1474 Video Surveillance 半平面交

和POJ 3130,POJ 3335一样.求多边形的核 #include <iostream> #include <cstdio> #include <cmath> #define eps 1e-18 using namespace std; const int MAXN = 105; double a, b, c; int n, cnt; struct Point { double x, y; }point[MAXN], p[MAXN], tp[MAXN]; void

POJ 3130 How I Mathematician Wonder What You Are!(半平面相交 多边形是否有核 模板)

题目链接:http://poj.org/problem?id=3130 Description 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 image processing program count stars. The hardest pa

POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)

题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. 1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <math.h> 5 6 using namespace std ; 7 8 struct node 9 { 10 double x; 11 d

POJ 3130 How I Mathematician Wonder What You Are! 半平面交求多边形内核是否存在

题目大意:定义一种多边形,叫做星形多边形.这种多边形就是有内核的多边形.给出一些多边形,问是否是星形多边形. 思路:利用半平面交求解.PS:我的第一个多边形内核的代码不对..一定要看这个,这个是我看了学长的代码之后才发现之前的代码的问题的,这个也不用微调,是准确值,总值千万不要去看前面的那篇!!!! 由于内核中的所有点到图形上所有点的连线之间不能有边阻挡,所以为了满足任意一条边,需要满足内核的点必须在这条边所在直线的左边,所以将所有组成多边形的边所在的直线进行半平面交即可.由于一个多边形的内核也

poj 3384 半平面交

Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5183   Accepted: 1548   Special Judge Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achieve harmony with the environment. George h