Bahiyyah has a convex polygon with nn vertices P0,P1,⋯,Pn−1P0,P1,⋯,Pn−1 in the counterclockwise order. Two vertices with consecutive indexes are adjacent, and besides, P0P0 and Pn−1Pn−1 are adjacent. She also assigns a point QQ inside the polygon which may appear on the border.
Now, Bahiyyah decides to roll the polygon along a straight line and calculate the length of the trajectory (or track) of point QQ.
To help clarify, we suppose Pn=P0,Pn+1=P1Pn=P0,Pn+1=P1 and assume the edge between P0P0 and P1P1 is lying on the line at first. At that point when the edge between Pi−1Pi−1 and PiPi lies on the line, Bahiyyah rolls the polygon forward rotating the polygon along the vertex PiPi until the next edge (which is between PiPi and Pi+1Pi+1) meets the line. She will stop the rolling when the edge between PnPn and Pn+1Pn+1 (which is same as the edge between P0P0 and P1P1) meets the line again.
The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.
For each test case, the first line contains an integer n (3≤n≤50)n (3≤n≤50) indicating the number of vertices of the given convex polygon. Following nn lines describe vertices of the polygon in the counterclockwise order. The ii-th line of them contains two integers xi−1xi−1 and yi−1yi−1, which are the coordinates of point Pi−1Pi−1. The last line contains two integers xQxQ and yQyQ, which are the coordinates of point QQ.
We guarantee that all coordinates are in the range of −103−103 to 103103, and point QQ is located inside the polygon or lies on its border.
For each test case, output a line containing Case #x: y, where x is the test case number starting from 11, and y is the length of the trajectory of the point QQ rounded to 33 places. We guarantee that 44-th place after the decimal point in the precise answer would not be 44 or 55.
4
4
0 0
2 0
2 2
0 2
1 1
3
0 0
2 1
1 2
1 1
5
0 0
1 0
2 2
1 3
-1 2
0 0
6
0 0
3 0
4 1
2 2
1 2
-1 1
1 0
Case #1: 8.886
Case #2: 7.318
Case #3: 12.102
Case #4: 14.537
分析:暴力附加两个数据,dp[0] = dp[n] , dp[n+1]=dp[1],按余弦定理计算就能AC。
#include#include #include #include <string> #include #include #include
分析:数学签到题,( 可以重点关注一下 小技巧 (i+1)%n 和 (i-1)%n )
#include#include #include #include <string> #include #include #include