产业转型升级包括:Problem 1. CLOSED FENCES

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/27 08:21:23
A CLOSED FENCE in the plane is a closed broken line with N corners and no intersections. The corners or vertices are listed in counter-clockwise order in an array {xi yi} i = 1,....N. Every pair of adjacent vertices defines a side of the fence. Thus {xi yi xi+1 yi+1 }is a side of the fence for i= 1,... N. Note that N+1=1 which connects the first and last vertices making the fence closed.

* x3 y3
x5 y5 / \
x y * * / \
/ \ / \
/ * \
x6 y6* x4 y4 \
| \
| \
x1 y1*----------------* x2 y2

Write a program which will do the following:
a) Test an array of vertices {xi yi }, i = 1,....N to see if the array is a valid fence. A valid fence is one that has no intersections.

b) Suppose a person (with no height) is standing in the plane at position (x y) and looks at the fence. What sides can the person see? The program must identify all sides of the fence that are visible or partially visible from (x y). This means there exists a ray from (x y) to the side which does not intersect any other side of the fence. A side that is parallel to the line of sight is not considered visible. In the figure above the segments x3 y3 x4 y4 and x5 y5 x6 y6 x1 y1 consisting of two sides are visible or partially visible from x y. If only part of a side is visible, the entire side should be listed in the visible segment. Do not list just the visible portion.

Input file: FENCE.DAT
Each data set in FENCE.DAT consists of:

a) N (the number of corners in the fence, N<=30)
b) A sequence of corners consisting of two integers (each with absolute value <100) separated by a space and every two adjacent corners also separated by a space. The corners are given in counter-clockwise order. The sequence can continue on a new line if necessary.
c) A position x y for the person observing the fence.

Output file: FENCE.SOL file .
The data set in FENCE.SOL consists of:

a) M (the number of visible sides).
b) A listing of each fence segment (one or more sides that are connected) with one segment per line.

or

a) The message "NO FENCE" if the sequence given in the FENCE.DAT is not a valid fence.

Different data sets will be separated by an empty record (that is, a line containing only the end of the line character.
要求源程序
最好用pascal

Output file: FENCE.SOL file .
The data set in FENCE.SOL consists of:

a) M (the number of visible sides).
b) A listing of each fence segment (one or more sides that are connected) with one segment per line.

or

a) The message "NO FENCE" if the sequence given in the FENCE.DAT is not a valid fence.

Different data sets will be separated by an empty record (that is, a line containing only the end of the line character.

Output file: FENCE.SOL file .
The data set in FENCE.SOL consists of:

a) M (the number of visible sides).
b) A listing of each fence segment (one or more sides that are connected) with one segment per line.

or

a) The message "NO FENCE" if the sequence given in the FENCE.DAT is not a valid fence.

Different data sets will be separated by an empty record (that is, a line containing only the end of the line character.