[原创]POJ 1066 Treasure Hunt [线段相交]【计算几何】
[原创]POJ 1066 Treasure Hunt [线段相交]【计算几何】
2016-04-10 18:36:31 Tabris_ 阅读数:549
博客爬取于2020-06-14 22:44:35
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/51114254
题目链接 :http://poj.org/problem?id=1066
Treasure Hunt
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 6260 Accepted: 2598
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
题目大意 :
有一个100*100大的封闭,有着一堆墙,墙的两端都在封闭空间的边上,在封闭空间内有一出宝藏,问你至少要打穿多少墙才能取得宝藏。
解题思路 :
在外围进入里面打多少墙就是计算从这堆墙的两端与宝藏处所连成的线段总共穿过了几道墙(其实想一想也能明白,两点之间直线最短,所以在这样的条件下穿过的墙数最少,就是最少的了),也就是判断一下线段相交,因为数据量并不是很大,所以暴力的枚举就好。
这里应用到了判断线段相交的方法
如果对此不是怎么了解的话可以看下这里:
华丽丽的传送阵:http://blog.csdn.net/qq_33184171/article/details/51114511
提示:
1.计算结果要加1,因为从封闭空间也是用墙封上的。
2.0的时候要特判下,这时结果为1。
附本题代码
1 | # include <iostream> |