2次AC。只需注意相同端点不用算通过一面墙,最后加上1即可。
//
// main.cpp
// Richard
//
// Created by 邵金杰 on 16/8/8.
// Copyright © 2016年 邵金杰. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define INF 1e20
#define EPS 1e-6
struct Point{
double x,y;
Point(double x,double y): x(x),y(y) {}
};
struct Vector{
double x,y;
Vector(double x,double y): x(x),y(y) {}
};
struct Line{
Point a,b;
Line(Point a,Point b): a(a),b(b) {}
};
Vector operator - (Point p,Point q)
{
return Vector(p.x-q.x,p.y-q.y);
}
Vector operator * (double k,Vector p)
{
return Vector(k*p.x,k*p.y);
}
Point operator + (Point p,Vector q)
{
return Point(p.x+q.x,p.y+q.y);
}
bool operator == (Point p,Point q)
{
return p.x==q.x&&p.y==q.y;
}
bool IsZero(double x)
{
return -EPS<x&&x<EPS;
}
bool FLessEq(double a,double b)
{
return b-a>EPS||IsZero(b-a);
}
double cross(Vector p,Vector q)
{
return p.x*q.y-p.y*q.x;
}
bool intersect(Line l,Line m)
{
double x=cross(l.a-m.a,m.b-m.a)/2;
double y=cross(m.b-m.a,l.b-m.a)/2;
if(IsZero(x+y)) return false;
if(l.a==m.a||l.a==m.b) return false;
if(l.b==m.a||l.b==m.b) return false;
Point d=l.a+(x/(x+y))*(l.b-l.a);
if(FLessEq(min(l.a.x,l.b.x),d.x)&&FLessEq(d.x,max(l.a.x,l.b.x))
&&FLessEq(min(l.a.y,l.b.y),d.y)&&FLessEq(d.y,max(l.a.y,l.b.y)))
return true;
return false;
}
vector<Point> ve;
vector<Line> le;
void work(double x,double y)
{
Point p=Point(x,y);
int doors=INF;
int lenv=(int)ve.size();
int lenl=(int)le.size();
for(int i=0;i<lenv;i++)
{
int cnt=0;
Line l=Line(p,ve[i]);
for(int j=0;j<lenl;j++)
{
if(intersect(l,le[j])) cnt++;
}
doors=min(doors,cnt);
}
printf("Number of doors = %d \n",doors+1);
}
int main()
{
int n;
double x1,y1,x2,y2,x,y;
scanf("%d",&n);
ve.push_back(Point(0,0));
ve.push_back(Point(100,0));
ve.push_back(Point(0,100));
ve.push_back(Point(100,100));
for(int i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
ve.push_back(Point(x1,y1));
ve.push_back(Point(x2,y2));
le.push_back(Line(Point(x1,y1),Point(x2,y2)));
}
scanf("%lf%lf",&x,&y);
if(n==0) printf("Number of doors = 1 \n");
else work(x,y);
return 0;
}