ZOJ 1648 线段相交

题意:

是否存在规范相交

 

View Code
 1 #include <iostream>

 2 #include <cstdlib>

 3 #include <cstdio>

 4 #include <cstring>

 5 #include <algorithm>

 6 #include <cmath>

 7 

 8 #define N 2020

 9 #define EPS 1e-4

10 //规范相交 

11 using namespace std;

12 

13 struct PO

14 {

15     double x,y;

16 };

17 

18 struct LI

19 {

20     PO a,b;

21 }li[N];

22 

23 int n;

24 

25 inline int doublecmp(double x)

26 {

27     if(x>EPS) return 1;

28     else if(x<-EPS) return -1;

29     return 0;

30 }

31 

32 inline double cross(PO &a,PO &b,PO &c)

33 {

34     return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);

35 }

36 

37 inline double dot(PO &a,PO &b,PO &c)

38 {

39     return (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);

40 }

41 

42 inline bool segcross(LI &a,LI &b)

43 {

44     int p1,p2,d1,d2;

45     //b跨立a 

46     p1=doublecmp(cross(a.a,a.b,b.a));

47     p2=doublecmp(cross(a.a,a.b,b.b));

48     //a跨立b 

49     d1=doublecmp(cross(b.a,b.b,a.a));

50     d2=doublecmp(cross(b.a,b.b,a.b));

51     if(p1*p2<0&&d1*d2<0) return true;

52     else return false;

53 }

54 

55 inline void read()

56 {

57     for(int i=1;i<=n;i++)

58         scanf("%lf%lf%lf%lf",&li[i].a.x,&li[i].a.y,&li[i].b.x,&li[i].b.y);

59 }

60 

61 inline void go()

62 {

63     for(int i=1;i<=n;i++)

64         for(int j=i+1;j<=n;j++)

65             if(segcross(li[i],li[j])) {puts("burned!");return;}

66     puts("ok!");

67 }

68 

69 int main()

70 {

71     while(scanf("%d",&n)!=EOF) read(),go();

72     return 0;

73 }

 

 

你可能感兴趣的:(ZOJ)