poj 1066 Treasure Hunt(判断线段相交)

Treasure Hunt
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4145   Accepted: 1708

Description

Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine that the lower floor of the pyramid is constructed from a series of straightline walls, which intersect to form numerous enclosed chambers. Currently, no doors exist to allow access to any chamber. This state-of-the-art technology has also pinpointed the location of the treasure room. What these dedicated (and greedy) archeologists want to do is blast doors through the walls to get to the treasure room. However, to minimize the damage to the artwork in the intervening chambers (and stay under their government grant for dynamite) they want to blast through the minimum number of doors. For structural integrity purposes, doors should only be blasted at the midpoint of the wall of the room being entered. You are to write a program which determines this minimum number of doors. 
An example is shown below: 

Input

The input will consist of one case. The first line will be an integer n (0 <= n <= 30) specifying number of interior walls, followed by n lines containing integer endpoints of each wall x1 y1 x2 y2 . The 4 enclosing walls of the pyramid have fixed endpoints at (0,0); (0,100); (100,100) and (100,0) and are not included in the list of walls. The interior walls always span from one exterior wall to another exterior wall and are arranged such that no more than two walls intersect at any point. You may assume that no two given walls coincide. After the listing of the interior walls there will be one final line containing the floating point coordinates of the treasure in the treasure room (guaranteed not to lie on a wall).

Output

Print a single line listing the minimum number of doors which need to be created, in the format shown below.

Sample Input

7 
20 0 37 100 
40 0 76 100 
85 0 0 75 
100 90 0 90 
0 71 100 61 
0 14 100 38 
100 47 47 100 
54.5 55.4 

Sample Output

Number of doors = 2 

Source

East Central North America 1999
题目: http://poj.org/problem?id=1066
题意:给你一些线段将一个正方形分割成一些封闭的格子,要求从正方形外,到一个给的的格子至少要穿过几条线段
分析:一开始看挺吓人的,再加上是计算几何,不过仔细分析了一会儿,发现由于题目的条件,每条线段必定连接到两个边界,所以有,你从一个边界上的一点进去,只要判断连接这一点到终点的线段与多少条线段相交,就必须穿过多少条线段,不管你怎么拐都无济于事。。。所以,水了,敲完模板就1Y了,最近正确率提升了哈,难道是每次都test()的原因??
代码:
#include
#include
#include
#include
using namespace std;
typedef double mType;
struct Tpoint
{
    mType x,y;
    Tpoint(){}
    Tpoint(mType _x,mType _y):x(_x),y(_y){}
};
struct Tsegment
{
    Tpoint start,end;
    Tsegment(){}
    Tsegment(Tpoint _start,Tpoint _end):start(_start),end(_end){}
    Tsegment(mType sx,mType sy,mType ex,mType ey):start(sx,sy),end(ex,ey){}
};
Tpoint MakeVector(Tpoint P,Tpoint Q)
{
    return Tpoint(Q.x-P.x,Q.y-P.y);
}
mType CrossProduct(Tpoint P,Tpoint Q)
{
    return P.x*Q.y-P.y*Q.x;
}
mType MultiCross(Tpoint P,Tpoint Q,Tpoint R)
{
    return CrossProduct(MakeVector(Q,P),MakeVector(Q,R));
}
bool IsIntersect(Tsegment P,Tsegment Q)
{
    if(max(P.start.x,P.end.x)=100)a[2][m[2]++]=y;
    if(y>=100)a[3][m[3]++]=x;
}
int solve(mType sx,mType sy)
{
    Tsegment tmp=Tsegment(sx,sy,X,Y);
    int i,ret=0;
    for(i=0;i


你可能感兴趣的:(计算几何)