标签:
#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; const int MAXN = 1e3+7; const int oo = 1e9+7; const double EPS = 1e-8; struct point { double x, y; point(double x=0, double y=0):x(x), y(y){} point operator - (const point &t) const{ return point(x-t.x, y-t.y); } int operator *(const point &t) const{ double ans = x * t.y - y * t.x; if(ans > EPS)return 1; if(fabs(ans) < EPS)return 0; return -1; } bool operator == (const point &t) const{ return fabs(x-t.x)<EPS && fabs(y-t.y)<EPS; } }; struct segment { point A, B; segment(point A=0, point B=0):A(A), B(B){} bool inter(const segment &t) const{ return (A-B)*(t.A-B) + (A-B)*(t.B-B) == 0; } }; int Find(segment a, segment sg[], int N) { int sum = 0; for(int i=0; i<N; i++) { if(a.inter(sg[i]) && sg[i].inter(a)) sum++; } return sum; } int main() { int N; while(scanf("%d", &N) != EOF) { int k=0, Min = oo; segment sg[MAXN]; point p[MAXN], End, A, B; for(int i=0; i<N; i++) { scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y); p[k++] = A, p[k++] = B; sg[i] = segment(A, B); } scanf("%lf%lf", &End.x, &End.y); for(int i=0; i<k; i++) { if(p[i] == End) continue; Min = min(Min, Find(segment(End, p[i]), sg, N)+1); } if(Min == oo)Min = 1; printf("Number of doors = %d\n", Min); } return 0; }
Treasure Hunt - POJ 1066(线段相交判断)
标签:
原文地址:http://www.cnblogs.com/liuxin13/p/4792196.html