AC is not dead的专栏

Intersection

You are to write a program that has to decide whether a given line segment intersects a given rectangle.

An example: line: start point: (4,9)

end point: (11,2)

rectangle: left-top: (1,5)

right-bottom: (7,1)

Figure:Line segment does not intersect rectangle

The line is said to intersect the rectangle if the line and the rectangle have at least one point in common. The rectangle consists of four straight lines and the area in between. Although all input values are integer numbers, valid intersection points do not have to lay on the integer grid.

Input

The input consists ofntest cases. The first line of the input file contains the numbern. Each following line contains one test case of the format:

where (xstart,ystart) is the start and (xend,yend) the end point of the line and (xleft,ytop) the top left and (xright,ybottom) the bottom right corner of the rectangle. The eight numbers are separated by a blank. The termsanddo not imply any ordering of coordinates.

Output

For each test case in the input file, the output file should contain a line consisting either of the letter "T" if the line segment intersects the rectangle or the letter "F" if the line segment does not intersect the rectangle.

Sample Input14 9 11 2 1 5 7 1Sample OutputF先判断线段所在直线是否穿过某一矩形对角线(1),若不穿过,则线段与矩形必不相交,,若穿过在判断线段两个端点是否在矩形的一侧,因为有了条件(1)则不在一侧时必与矩形相交,否则不相交。

美好的生命应该充满期待、惊喜和感激

AC is not dead的专栏

相关文章:

你感兴趣的文章:

标签云: