POJ1474 Video Surveillance(半平面交)

很多道相似的半平面交,但只过了这个,心都碎了。。

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

#pragma warning(disable:4996)

#include <iostream>

#include <cstring>

#include <cstdio>

#include <vector>

#include <cmath>

#include <string>

#include <algorithm>

using
namespace std;

#define maxn 2500

#define eps 1e-7

int
n;

int
dcmp(double
x){

    return
x<-eps ? -1 : x>eps;

}

struct
Point

{

    double
x, y;

    Point(){}

    Point(double
_x, double
_y) :x(_x), y(_y){}

    Point operator + (const
Point &b) const{

        return
Point(x + b.x, y + b.y);

    }

    Point operator - (const
Point &b) const{

        return
Point(x - b.x, y - b.y);

    }

    Point operator *(double
d) const{

        return
Point(x*d, y*d);

    }

    Point operator /(double
d) const{

        return
Point(x / d, y / d);

    }

    double
det(const
Point &b) const{

        return
x*b.y - y*b.x;

    }

    double
dot(const
Point &b) const{

        return
x*b.x + y*b.y;

    }

    Point rot90(){

        return
Point(-y, x);

    }

    Point norm(){

        double
len = sqrt(this->dot(*this));

        return
Point(x, y) / len;

    }

    void
read(){

        scanf("%lf%lf", &x, &y);

    }

};

#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))

#define crossOp(p1,p2,p3) (dcmp(cross(p1,p2,p3)))

Point isSS(Point p1, Point p2, Point q1, Point q2){

    double
a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);

    return
(p1*a2 + p2*a1) / (a1 + a2);

}

struct
Border

{

    Point p1, p2;

    double
alpha;

    void
setAlpha(){

        alpha = atan2(p2.y - p1.y, p2.x - p1.x);

    }

};

bool
operator < (const
Border &a, const
Border &b) {

    int
c = dcmp(a.alpha - b.alpha);

    if
(c != 0) {

        return
c > 0;

    }

    else
{

        return
crossOp(b.p1, b.p2, a.p1) > 0;

    }

}

bool
operator == (const
Border &a, const
Border &b){

    return
dcmp(a.alpha - b.alpha) == 0;

}

Point isBorder(const
Border &a, const
Border &b){

    return
isSS(a.p1, a.p2, b.p1, b.p2);

}

Border border[maxn];

Border que[maxn];

int
qh, qt;

// check函数判断的是新加的半平面和由a,b两个半平面产生的交点的方向,若在半平面的左侧返回True

bool
check(const
Border &a, const
Border &b, const
Border &me){

    Point is = isBorder(a, b);

    return
crossOp(me.p1, me.p2, is) >= 0;

}

bool
isParellel(const
Border &a, const
Border &b){

    return
dcmp((a.p2 - a.p1).det(b.p2 - b.p1)) == 0;

}

bool
convexIntersection()

{

    qh = qt = 0;

    sort(border, border + n);

    n = unique(border, border + n) - border;

    for
(int i = 0; i < n; i++){

        Border cur = border[i];

        while
(qh + 1 < qt&&!check(que[qt - 2], que[qt - 1], cur)) --qt;

        while
(qh + 1 < qt&&!check(que[qh], que[qh + 1], cur)) ++qh;

        que[qt++] = cur;

    }

    while
(qh + 1 < qt&&!check(que[qt - 2], que[qt - 1], que[qh])) --qt;

    while
(qh + 1 < qt&&!check(que[qh], que[qh + 1], que[qt - 1])) ++qh;

    return
qt - qh > 2;

}

Point ps[maxn];

int
main()

{

    int
ca = 0;

    while
(cin >> n&&n)

    {

        for
(int i = 0; i < n; i++){

            ps[i].read();

        }

        ps[n] = ps[0];

        for
(int i = 0; i < n; i++){

            border[i].p1 = ps[i + 1];

            border[i].p2 = ps[i];

            border[i].setAlpha();

        }

        printf("Floor #%d\n", ++ca);

        if
(convexIntersection()) {

            puts("Surveillance is possible.");

        }

        else
puts("Surveillance is impossible.");

        puts("");

    }

    return
0;

}

时间: 2024-10-12 16:31:27

POJ1474 Video Surveillance(半平面交)的相关文章

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

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

POJ 1474 Video Surveillance 半平面交求多边形内核存在性

题目大意:一个楼有很多层,每一层是一个多多边形,问每一层是否有点能够看到这一层的全貌. 思路:半平面交解多边形内核存在性,裸题.题中怎么没写数据范围?..让我还re几次.. CODE: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 3010 #define EPS 1e-8 #de

poj1474Video Surveillance(半平面交)

链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. 1 #include<iostream> 2 #include <stdio.h> 3 #include <math.h> 4 #define eps 1e-8 5 using namespace std; 6 const int MAXN=210; 7 int m; 8 double r; 9 int cCnt,curCnt;//此时cCnt为最终切割得到的多边形的顶

poj-1474 Video Surveillance

题意: 判断多边形是否存在核: 点集顺时针或逆时针给出,n<=100: 题解: 半平面交模板题: 多边形的核就在组成多边形的半平面的交上: 也可以顺便说明多边形的核若存在则一定是凸的: 原因似乎画画图是比较显然的: 一个地方被挡住一定是因为那被另一条边挡住了嘛: 注意半平面交的判断点与直线位置关系要用>=号: 此题买一送二,我大胆地在提交框里改输出然后光荣的WA了= = poj-1474 poj-3130 poj-3335 代码: #include<math.h> #include

poj1474 Video Surveillance

题意:求多边形的内核,即:在多边形内部找到某个点,使得从这个点能不受阻碍地看到多边形的所有位置. 只要能看到所有的边,就能看到所有的位置.那么如果我们能够在多边形的内部的点x看到某条边AB,这个点x一定在AB的"内侧",如果按逆时针方向给出多边形的所有顶点并假设从A到B是逆时针行走,"内侧"就是指有向直线A->B的左侧,那么多边形的每条边对应了一个半平面,要想看见这条边必须保证x在这个半平面内.而且,只要对于每条边x都在这条边的左侧,那么x就是一个可行的点,能

Video Surveillance POJ - 1474 (半平面交)

Video Surveillance POJ - 1474 题意:多边形是否有内核 思路:平面半交题,注意直线的存入顺序 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 typedef long long l

poj 1474 Video Surveillance (半平面交)

链接:http://poj.org/problem?id=1474 Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3247   Accepted: 1440 Description A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment

uva 588 - Video Surveillance(半平面相交)

题目链接:uva 588 - Video Surveillance 求出多边形的核,如果非0即为可行,注意核退化成直线和点都是可以的,所以不能用面积去判断. #include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <complex> #include <algorithm> using namespace std; typedef

POJ 1474 多边形的核(半平面交)

Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3145   Accepted: 1391 Description A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment store. One of his tasks is to ins