0% found this document useful (0 votes)
75 views

TCS - CodeVita - Coding Arena-E

The document describes a coding problem about determining the shortest path a bug can take to travel between two points on a cylindrical water cistern. The cistern has a height, radius, and the bug's starting point is at a distance from the top. The destination point is given as coordinates, and the goal is to calculate the shortest distance between the starting and destination points.

Uploaded by

Yogesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

TCS - CodeVita - Coding Arena-E

The document describes a coding problem about determining the shortest path a bug can take to travel between two points on a cylindrical water cistern. The cistern has a height, radius, and the bug's starting point is at a distance from the top. The destination point is given as coordinates, and the goal is to calculate the shortest distance between the starting and destination points.

Uploaded by

Yogesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8/9/2018 TCS: CodeVita - Coding Arena

Jaimanish Jayamurthy

05 Hr 46 Min Coding Area


30 Sec
A B C D E F

Guidelines
ONLINE EDITOR (E)
Coding Area Water Cistern
Editor | Compile & Problem Description
Run History
A cylindrical water cistern was built in an apartment complex in
Submissions Aquatown.

Feedback Form

Result

Graphs

The bottom rests on concrete and is not accessible. It has a height h and
a radius r,

A mathematical bug is sitting on the cistern at point A, and has


established a coordinate system to cover the entire accessible area. The
bug is sitting a distance s from the top of the cistern, and the nearest
point at the top is B.

For a point C on the curved surface, the nearest point D on the top is
determined, and the distance CD is taken as t. The angle p (in degrees)
subtended at the centre of the circle E by the arc BD is measured (in a
counterclockwise manner). The coordinates of C are taken as the pair
(t,p), with t being greater than 0 and less than h, and with p being between
0 and 359 (inclusive).

For a point on the top surface, F, the distance to the centre E is taken (a),
and the counterclockwise angle (in degrees) between EB and EF is taken.
The coordinates of the point F are then taken as (-a,q). The value of a is
between 0 and r, and the value of q is between 0 and 359.

https://www.tcscodevita.com/CodevitaV7/main_page.jsp 1/3
8/9/2018 TCS: CodeVita - Coding Arena

All coordinates are integers, and if the point is on the top surface of the
cylinder, the first coordinate is negative, and if it is on the curved surface
of the cylinder, the first coordinate is positive.

From its staring point A, the bug needs to go to its destination, which is a
point (like C or F) either on the curved surface or the top surface. The
coordinates of the destination are given. The bug would like to go by the
shortest path to its destination.

The goal is to determine the length of the shortest path the bug can take.

Constraints
40<s<=h<10000

r<100

0<=g<=359

If d is negative, d > -r

If d is positive, d < h

Input Format
The first line has three comma separated positive integers giving r (the
radius), h (the height of the cylinder) and s (the distance from the top of
the starting point of the bug)

The next line has two comma separated integers (d and g) giving the
coordinates of the destination. If the first integer (d) is negative, it is on
top surface of the cylinder, and else it is on the curved surface of the
cylinder

Output
The output is a single integer giving the shortest distance that the bug can
travel. The computed distance must be rounded to the nearest integer

Explanation
Example 1

Input

100,500,200

200,180

Output

314

Explanation

The value of r is 100, and h is 500. The distance of the bug from the top
surface is 200.

https://www.tcscodevita.com/CodevitaV7/main_page.jsp 2/3
8/9/2018 TCS: CodeVita - Coding Arena

The coordinates of the destination are (200,180). As the first coordinate is


200, the destination is on the curved surface (like point C), and at the
same distance from the top surface as the bug. As the second coordinate
is 180, the destination is exactly on the other side of the cylinder at the
same height as the bug, The distance is half the circumference of the
cylinder, or 314. This is the output.

Example 2

Input

100,500,200

-50,180

Output

350

Explanation

The value of r is 100, and h is 500. The distance of the bug from the top
surface is 200.

The coordinates of the destination are (-50,180). As the first coordinate is


negative (-50), the point is on the top surface of the cylinder (like point F),
and EF is 50. As the second coordinate is 180, BEF is a straight line. The
distance travelled is AB + BE + EF = 200 + 100 + 50=350. This is the
output.

Upload Solution [ Question : E ]


I, jaimanish jayamurthy confirm that Took help from online sources
the answer submitted is my own. (attributions)
Choose a
File ...

CodeVita FAQ's
CONNECT WITH US
CodeVita Blog
Privacy Policy
Careers

© 2018 Tata Consultancy Services


Limited. All Rights Reserved.

https://www.tcscodevita.com/CodevitaV7/main_page.jsp 3/3

You might also like