Introduction
TCS organizes CodeVita every year, in which any graduate student can participate and give their all. It is used to encourage competitive programming and to help you improve your programming skills. In addition, top scorers are allowed to interview for job openings with TCS. The first CodeVita was held in India in 2012 to raise awareness about competitive coding and various applications and codings.
In this blog, we will solve a sample question from TCS CodeVita but before that, if you are looking for a complete guide on how to Crack TCS NQT & Hack With Infy and Get Placement Offers, refer to the following video.
(Also see Data Structures)
Problem Description
A 10cm x 10cm x 10cm solid cube rests on the ground. It has a beetle on it, as well as some sweet honey spots on the cube's surface. The beetle begins at a point on the cube's surface and moves in a clockwise direction along the cube's surface to the honey spots.
1. If it goes from one point on the same face to another (say, X to Y), it goes in an arc of a circle that subtends an angle of 60 degrees at the circle's center.
2. If it travels from one point to another on a different face, it takes the shortest path on the cube's surface, except that it never travels along its bottom.
The beetle is a Cartesian geometry student who knows the coordinates (x, y, z) of all the points it needs to visit. Its coordinate origin is one of the cube's corners on the ground, and the z-axis points up. As a result, z=0 is the bottom surface (on which it does not crawl), and z=10 is the top. The beetle keeps track of all distances traveled and rounded the distance to two decimal places when it arrives at the following location so that the final distance is a sum of the rounded distances from spot to spot.
Input
The first line returns an integer N, the total number of points visited by the beetle (including the starting point).
The second line contains 3N non-negative numbers, each with two decimal places. These are to be interpreted as the x, y, and z coordinates of the points the beetle must visit in the given order.
Output
One line contains a number representing the total distance traveled by the beetle to two decimal places. Even if the travel distance is an integer, the output should have two decimal places.
Constraints
None of the points visited by the beetle are on the bottom face (z=0) or on any of the cube's edges (the lines where two faces meet)
2<=N<=10
Difficulty Level
Complex
Time Limit (secs)
1
Sample Examples
Example 1
Input
3
1 1 10 2 1 10 0 1 9
Output
4.05
Explanation
The beetle visits three different locations (N=3). The beetle begins on the cube's top face (z=10) at point (1,1,10) and moves to another point on the same face (2,1,10). Although the straight line distance is one, it travels on the arc of a circle with an angle of 60 degrees at its center and thus travels (2*pi)/6 or 1.05 (note that it rounds the distance at each leg of the journey). It moves along the cube's surface from (2,1,10) on the face z=10 to (0,1,9) on the face x=0. This is a three-mile distance. The total travel distance is 1.05+3=4.05. The result is 4.05
Example 2
Input
3
1 1 10 2 1 10 0 5 9
Output
6.05
Explanation
The beetle visits three different locations (N=3). The beetle begins on the cube's top face (z=10) at point (1,1,10) and moves to another point on the same face (2,1,10). The same as before. This distance is 1.05 miles. It moves along the cube's surface from (2,1,10) on the face z=10 to (0,5,9) on the face x=0. The shortest distance between these points on the cube's surface is 5. 1.05+5=6.05 is the total distance traveled. The result is 6.05.




