code vita 2018 questiones

1)

Circles and Distances

Problem Description

Task is to calculate the straight line distance between the two objects moving in a circular path. They may move at different velocities. The distance has to be calculated after N seconds.
The figure and commentary below it, explains the problem in detail.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@491cde5b:image1.png
We have two point objects B and C at rest on a straight line at a distance r1 and r2 units from a point A. At time t=0 seconds, the objects start moving in a circular path with A at the center with velocity v1 and v2 degrees per second.
Given inputs v1, v2, r1 and r2, calculate the distance between the B and C after N seconds.
Distance should be printed up to an accuracy of 2 places after the decimal point. Use Rounding Half-up semantics.

Input Format

First line contains velocity of object B in degrees per second (v1)
Second line contains distance of object B from A (r1)
Third line contains velocity of object C in degrees per second (v2)
Fourth line contains distance of object C from A (r2)
Fifth line contains time in seconds after which the distance between B and C, is to be measured (N)

Output

The distance between B and C, N seconds after they are set in motion
Constraints
v1, v2, r1, r2 > 0 and all are integer values.
r2 > r1
0 < n <= 100
The objects move in anticlockwise direction
v1, v2 <=360
r2 <= 100

Explanation

Example 1
Input
90
5
270
10
1
Output
15.00
Explanation
After 1 second, the object at B would cover 90 degrees and the object at C would cover 270 degrees. Both the objects would be vertically opposite to each other and would lie in a straight line.
So the distance between them would be equal to the sum of their distance from the origin A=5+10= 15 units


2)

Wind Farm Optimization

Problem Description

Government of India has an ambitious plan to have electricity surplus by using renewable energy sources. Mr. Tripathi is in-charge of meeting electricity generation using windmills. He has ordered quotations from two companies. In interest of future proofing investment he has decided that he will at least install one windmill from both vendors so that he is able to collect feedback about both windmills. He has a fixed budget B and fixed land parcel L. Help him to maximize electricity generation without exceeding budget and within constraints of land available.
Note: Area occupied by one windmill is 2*radius*radius, air density = 1.23 kg/m and generated power is in MegaWatt.
Use the following formula for Power Generation
Power Generated = (1/2) * Air Density * Area of Windmill * Velocity ^ 3 * Efficiency Coefficient

Constraints

None

Input Format

Radius of windmill provided by company A in meters
Cost per windmill provided by company A
Efficiency of windmill provided by company A
Radius of windmill provided by company B in meters
Cost per windmillprovided by company B
Efficiency of windmill provided by company B
Total budget B
Total land available L
Wind speed in meters/ second

Output

Theoretical Power generated (In MegaWatt)
Largest number of wind mills from company A and largest number of windmills from company B delimited by <space> that could be commissioned so that we get as near the Power generated as possible.
Actual Power generated (in MegaWatt)

Explanation

Example 1
Input
25
40000
0.56
35
800000
0.52
22000000
60000
11.5
Output
49.22
46
1
49.18
Explanation
Company A’'s specs are [25, 40000, 0.56] and Company B’'s specs are [35, 800000, 0.52] where the specs correspond to [radius of windmill, cost of installing one unit, efficiency factor]. Mr. Tripathi has 22M in budget and a land parcel of 60K units. Wind speed is 11.5 m/sec. First electricity generation and space taken by each windmill type in computed. Next, upon performing optimization, the wind farm will be able to generate ~49.22 MegaWatts of electricity if it installs 46.04 windmills of company-A type and 1 windmill of company-B type. However since number of windmills should be integral the output should be 46 and 1. Hence the actual power generated is 49.18 MW
Hint: - Find the max MW that can be generated, then round down the number of windmills so that the output is integral number of windmills. Then find actual power generated.
Example 2
Input
39.5
30000
0.52
37.5
32000
0.59
225000
65500
11.5
Output
17.78
6
1
16.74
Explanation
Company A’'s specs are [39.5, 30000, 0.52] and Company B'’s specs are [37.5, 32000, 0.59] where the specs correspond to [radius of windmill, cost of installing one unit, efficiency factor]. Mr. Tripathi has 225K in budget and a land parcel of 65.5K units. Wind speed is 11.5 m/sec. First electricity generation and space taken by each windmill type in computed. Next, upon performing optimization, the wind farm will be able to generate ~17.78MegaWatts of electricity if it installs 6.43 windmills of company-A type and 1 windmill of company-B type. However since number of windmills should be integral the out should be 6 and 1. Hence the actual power generated is 16.74 MW
Hint: - Find the max MW that can be generated, then round down the number of windmills so that the output is integral number of windmills. Then find actual power generated.
3)

Jurrasic Park

Problem Description

Smilodon is a ferocious animal which used to live during the Pleistocene epoch (2.5 mya–10,000 years ago). Scientists successfully created few smilodons in an experimental DNA research. A park is established and those smilodons are kept in a cage for visitors.
This park consists of Grasslands(G), Mountains(M) and Waterbodies(W) and it has three gates (situated in grasslands only).Below is a sample layout.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@1497cba8:image1.png
Before opening the park, club authority decides to calculate Safety index of the park. The procedure of the calculation is described below. Please help them to calculate.
Safety Index calculation
Assume a person stands on grassland(x) and a Smilodon escapes from the cage situated on grassland(y). If the person can escape from any of those three gates before the Smilodon able to catch him, then the grassland(x) is called safe else it is unsafe. A person and a Smilodon both takes 1 second to move from one area to another adjacent area(top, bottom, left or right) but a person can move only over grasslands though Smilodon can move over grasslands and mountains.
If any grassland is unreachable for Smilodon(maybe it is unreachable for any person also), to increase safe index value Club Authority use to mark those grasslands as safe land. Explained below
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@1497cba8:image2.png
For the above layout, there is only one gate at (4,6)
Y is the position of Smilodon’s cage
X is not safe area
Z is a safe area as is it not possible for smilodon to reach z
Safety index=(total grassland areas which are safe*100)/total grassland area

Constraints

3<= R,C <= 10^3
Gates are situated on grasslands only and at the edge of the park
The cage is also situated in grassland only
The position of the cage and the position of three gates are different

Input Format

The first line of the input contains two space-separated integers R and C, denoting the size of the park (R*C)
The second line contains eight space-separated integers where
First two integers represent the position of the first gate
3rd and 4th integers represent the position of second gate
5th and 6th integers represent the position of third gate respectively
The last two integers represent the position of the cage
Next R lines, each contains space separated C number of characters. These R lines represent the park layout.

Output

Safety Index accurate up to two decimal places using Half-up Rounding method

Explanation

Example 1
Input
4 4
1 1 2 1 3 1 1 3
G G G G
G W W M
G G W W
M G M M
Output
75.00
Explanation
G
G
G
G
G
W
W
M
G
G
W
W
M
G
M
M

Mountains
4

Gates- Safe Areas
3

Other Safe Areas
3

Waters
4

Cage Pos.-unsafe
1

Other unsafe areas
1
Safety Index= (6*100)/8
Example 2
Input
4 6
1 6 3 6 4 6 3 4
W M G G G G
M G W G M M
G W G G G G
W G W M W G
Output
69.23
4)

Bank Compare

Problem Description

There are two banks; Bank A and Bank B. Their interest rates vary. You have received offers from both bank in terms of annual rate of interest, tenure and variations of rate of interest over the entire tenure.
You have to choose the offer which costs you least interest and reject the other.
Do the computation and make a wise choice.
The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :
EMI = loanAmount * monthlyInterestRate /
( 1 - 1 / (1 + monthlyInterestRate)^(numberOfYears * 12))

Constraints

1 <= P <= 1000000
1 <=T <= 50
1<= N1 <= 30
1<= N2 <= 30

Input Format

First line : P – principal (Loan Amount)
Second line : T – Total Tenure (in years).
Third Line : N1 is number of slabs of interest rates for a given period by Bank A. First slab starts from first year and second slab starts from end of first slab and so on.
Next N1 line will contain the interest rate and their period.
After N1 lines we will receive N2 viz. the number of slabs offered by second bank.
Next N2 lines are number of slabs of interest rates for a given period by Bank B. First slab starts from first year and second slab starts from end of first slab and so on.
The period and rate will be delimited by single white space.

Output

Your decision – either Bank A or Bank B.

Explanation

Example 1
Input
10000
20
3
5 9.5
10 9.6
5 8.5
3
10 6.9
5 8.5
5 7.9
Output
Bank B
Example 2
Input
500000
26
3
13 9.5
3 6.9
10 5.6
3
14 8.5
6 7.4
6 9.6
Output
Bank B
5)

Orchard

Problem Description

There is a large orchard containing apple trees that is coming up for sale. You want to bid for the same but you need to count the number of trees in the orchard so that you can arrive at a reasonable bid. The orchard is quite huge. While the boundaries are straight lines, the area covered by the orchard is a polygon. The polygon is simple (the sides will not intersect) but may not be convex (the interior angles may be more than 180 degrees) However, if you introduce a coordinate system inside the orchard, with the origin at a tree, all the trees are uniformly located at all points whose both coordinates are even integers. (Note that an integer is said to be even if the absolute value is even; hence -6 and 0 are even, -3 is not). The corner points of the boundaries are also at points whose coordinates are even integers. Given the coordinates of the corner points of the boundary, write a program to count the number of trees in the orchard.

Constraints

4<= N<= 50

Input Format

The first line contains an integer N which gives the number of boundary corners.
The next N lines each contain two comma separated integers giving the coordinates of the boundary corners in clockwise order (so that the interior of the orchard is always on the right when going from one point to the next).

Output

One integer giving the number of trees in the orchard (including the trees on the boundary).

Explanation

Example 1
Input
7
-4,-2
-4,2
-6,6
2,2
8,4
6,-4
6,2
Output
17
Explanation
The polygon AGFEDCB is shown below. Trees are planted at points where the x and y coordinates are even, and the corner points are also even.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@9d5df31:image1.png
As can be seen, the number of trees on the boundary are 11, and the number of trees in the interior is 6, giving a total of 17 trees.
Example 2
Input
7
-2,-4
-4,-6
-6,4
0,0
6,6
8,-6
4,-4
Output
28
Explanation
The polygon ABCDEFG is shown below. The trees are on the corner points, and the boundary and interior points which have both x and y coordinates even.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@9d5df31:image2.png
There are 11 boundary trees and 17 interior trees. Hence the output is 28.
6)

Special Triangles

Problem Description

When we have 4 lines in the plane, the maximum number of triangles formed by them is 4 as shown below:
Of the four triangles ABF, CDF, BDE, ACE, triangles BDE and CDF are somewhat “special”. They do not have another of the given lines go through their interiors.
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@601c7012:image1.png
Given n lines in the plane, the objective is to count the number of special triangles formed by them. You may assume that no three lines will be concurrent (go through the same point). Each line will be specified by two points (x and y coordinates of two points on the line).
Note that three lines may not form a triangle, let alone a special triangle, if two of them are parallel lines.

Constraints

N<=15
Each of the x and y coordinates of the points defining any line lies between -10 and 10.

Input Format

The first line will have a single integer, N, representing the number of lines in the input.
The next N lines will have four comma separated numbers representing x1, y1, x2, y2 (the x and y coordinates of the two points on the line.

Output

The output is a single line giving the number of special triangles formed.

Explanation

Example 1
Input
4
1,2,4,7
2,3,2,5
3,5,7,5
4,7,3,4
Output
2
Explanation
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@601c7012:image2.png
Line I is defined by the points (1,2) (A) and (4,7) (B). Similarly, line II is defined by C (2,3) and D (2,5), line III by E (3,5) and F(7,5) and line IV by B (4,7) and G (3,4).
Of the four triangles formed by the four lines, the ones by (I,II,III) and (I,III,IV) are special.
(I,II,IV) has III going through the interior, while (II,III,IV) has I going through the interior.
As only two triangles are special, the output is 2.
Example 2
Input
4
2,2,3,2
2,3,3,3
2,4,3,4
2,5,3,5
Output
0
Explanation
As all lines are parallel to the x axis, there are no triangles, and hence no special triangles. The output is 0.

Comments

Popular posts from this blog

December Circuits '18 || Hakerearth || Picking coins

Detoll and Mom kit for free