Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Mothy
Description Mothy is a small moth. Mothy and his mother are placed on a very old pair of jeans. Because the jeans are very old they are covered with patches. Sometimes the patches overlap each other. Every patch is a convex polygon and is made by some material different from cotton. Mothy wants to go to his mother in the fastest possible way. He cannot move without eating and because of his age he cannot eat anything except jeans and cotton thread. Despite his age Mothy is very intelligent, he can move following precise coordinates but he is unable to compute them. Write a program that calculates the length of the minimal path from the position of Mothy to the position of his mother. Mothy must be able to pass through this path. Consider that the pair of old jeans is placed on a plane surface and is big enough. Mothy can move only at the surface of the jeans because he is not big enough to penetrate through them.
Because Mothy is so small he should be considered as a point. Mothy also can move on the edges of any of the patches because they are sewed with cotton threads. Mothy can move on common edges but cannot be on top of any patch. Input The first line of input contains a single integer T indicating the number of test cases. Each test case starts with number N of patches, and four integer numbers – the coordinates X and Y of Mothy’s position and coordinates U and V of his mother’s position, separated by white spaces (-10000 <= X, Y, U, V <= 10000). Each patch is described on a separate line starting with the number of vertices and followed by a pair of integer coordinates (-10000 <= Xi, Yi <= 10000) for each of the vertices of the patch, separated by white spaces. The total number of vertices of polygons will not exceed 300. Output For each of the test cases program has to output on a separate line the length of the shortest path between Mothy and his mother. The result should be rounded to 3 digits after the decimal point. The program has to output -1 if Mothy cannot reach his mother. Sample Input 2 1 0 0 4 3 3 1 1 4 4 1 4 2 0 0 5 5 4 1 0 4 0 4 1 1 2 3 3 3 4 4 5 2 Sample Output 5.000 7.236 Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator