该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
样题 1:
On ACube
A solid cube of 10 cm x 250px x10 cm rests on the ground. It has a beetle on it, and some sweethoney spots at various locations on the surface of the cube. The beetlestarts at a point on the surface of the cube, and goes to the honey spots inorder along the surface of the cube.
ProblemDescription
A solid cube of 10 cm x 250px x10 cm rests on the ground. It has a beetle on it, and some sweethoney spots at various locations on the surface of the cube. The beetlestarts at a point on the surface of the cube, and goes to the honey spots inorder along the surface of the cube.
1. Ifit goes from a point to another point on the same face (say X to Y), it goes inan arc of a circle that subtends an angle of 60 degrees at the centre of thecircle
2. Ifit goes from one point to another on a different face, it goes by the shortestpath on the surface of the cube, except that it never travels along the bottomof the cube
The beetle is a student ofCartesian geometry, and knows the coordinates (x, y, z) of all the points itneeds to go to. The origin of coordinates it uses is one corner ofthe cube on the ground, and the z axis points up. Hence, the bottomsurface (on which it does not crawl) is z=0, and the top surface isz=10. The beetle keeps track of all the distances travelled, androunds the distance travelled to two decimal places once it reaches the nextspot, so that the final distance is a sum of the rounded distances from spot tospot.
Input
The first line gives an integerN, the total number of points (including the starting point) the beetle visits
The second line is a set of 3Ncomma separated non-negative numbers, with up to two decimal placeseach. These are to be interpreted in groups of three as the x, y, zcoordinates of the points the beetle needs to visit in the given order.
Output
One line with a number givingthe total distance travelled by the beetle accurate to two decimalplaces. Even if the distance travelled is an integer, the outputshould have two decimal places.
Constraints
None of the points the beetlevisits is on the bottom face (z=0) or on any of the edges of the cube (thelines where two faces meet)
2<=N<=10
Complexity
Complex
TimeLimit
1
Examples
Example 1
Input
3
1,1,10,2,1,10,0,1,9
Output
4.05
Explanation
There are three points visitedby the beetle (N=3). The beetle starts on the top face of the cube (z=10) atpoint (1,1,10) and goes to another point on the same face(2,1,10). Though the straight line distance is 1, it travels on thearc of a circle subtending an angle of 60 degrees at the centre of the circle,and hence travels (2*pi)/6 or 1.05 (note that it rounds the distance at eachleg of the journey). It then travels from (2,1,10) on the face z=10to (0,1,9) on the face x=0 along the surface of the cube. This is a distance of3. The total distance travelled is 1.05+3=4.05. Theoutput is 4.05
Example 2
Input
3
1,1,10,2,1,10,0,5,9
Output
6.05
Explanation
There are three points visitedby the beetle (N=3). The beetle starts on the top face of the cube (z=10) atpoint (1,1,10) and goes to another point on the same face(2,1,10). As before. This distance is 1.05. It thentravels from (2,1,10) on the face z=10 to (0,5,9) on the face x=0 along thesurface of the cube. The shortest distance on the surface of the cube betweenthese points is 5. The total distance travelled is1.05+5=6.05. The output is 6.05.