POJ1066-Treasure Hunt

Treasure Hunt
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5407   Accepted: 2232

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 
//AC代码
 
  
/*
题意:说白点就是一张图,里面有许多交叉的线【也可以说墙】(线的两端只能落在外围的四条边上并且不存在两条相同的线和三条线交于同一点)
这些线组成许多密闭的空间,其中一个密闭空间中藏有宝藏,问你怎样炸掉最少的墙到宝藏处,起点是从外围的四条线(四条线的坐标固定,题目给了)任意点进入
思路:其实题目上说要从每个内墙的中点进入,但是仔细想一想不管从不从中点你不可能“绕过”这堵墙,所以从墙的两个端点进入和中点进入效果一样的,所以题目就可以简化成
从给出线段交与外围墙上的每个端点与所有所给线的交点(除了本身)最少数目再加上外围一堵墙(即+1)就是题目所求
*/

#include
#include
#include
#include
#include
#include
#define eps 1e-8
const int Max=101;
int sum[Max];
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
}point;
point s[Max];
double multi(point p0,point p1,point p2)//叉积
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
//相交返回true,否则为false,接口为两线段的端点
bool IsIntersected(point s1,point e1,point s2,point e2)//两个线段相交
{
	return(max(s1.x,e1.x)>=min(s2.x,e2.x))&& (max(s2.x,e2.x)>=min(s1.x,e1.x))&&(max(s1.y,e1.y)>=min(s2.y,e2.y))&&(max(s2.y,e2.y)>=min(s1.y,e1.y))&&(multi(s1,s2,e1)*multi(s1,e1,e2)>0)&&(multi(s2,s1,e2)*multi(s2,e2,e1)>0);
}
int main()
{
    int n,i,j;
    point ed;
    //while(1)
    //{
        cin>>n;
        memset(sum,0,sizeof(sum));
        for(i=1;i<=2*n;i+=2)
        {
            cin>>s[i].x>>s[i].y>>s[i+1].x>>s[i+1].y;
        }
        cin>>ed.x>>ed.y;
        for(i=1;i<=2*n;i++)
        {
            for(j=1;j<=2*n;j+=2)
            {
                if(i!=j)
                {
                    if(IsIntersected(s[i],ed,s[j],s[j+1]))
                        sum[i]+=1;
                }
            }
        }
        if(n>0)
        sort(sum+1,sum+(2*n));
        if(n!=0)
        cout<<"Number of doors = "<

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