You are on page 1of 4

KMIT – ARJUNA

Season-4
KMIT-APA-4008 Programming Assignments Sunday 29​th​ Sept, 2019

1 Toss Coin Win Diamonds


Duryodhan and Shakuni have devised a new coin tossing game *Diamond Hunt*. They invited Yudhisthir
to play the new game. They told him, in this game, a player is given a target number and he must toss a
gold coin to reach exactly the given target and win diamonds equal to the target.
Rules of the game are as follows:
● There would be a gold coin that has ​L​ion​ ​or ​D​eer​ engraved on each side.
● There would be two scoring points. DiamondPoints (DP) and LuckFactor (LF). Initially, DP is set to
0 and LF is set to 1.
● The player can shall, for n consecutive times, toss a gold coin to score DiamondPoints (DP).
● After every toss, based on the outcome i.e., Lion or Deer, the values of DP and LF are updated.
o If it is ​L​ion then the current values of LF is added to the current value of DP and then LF
is doubled.
o If it is ​D​eer and if the current value of DP is greater than 0 then LF is set to -1 otherwise
it is set to 1. No change to DP.
● The one who makes less tosses and reach the target number shall win the game.

Now, Yudhisthir is cautious this time and just wants to win the game. So, he requested you to write a
program to find the length of the minimum sequence of ​L​ions or ​D​eers to reach the given target
number.
Input/Output
Input Output Comments
5 7 ● 5​ is the target given​.
● The shortest sequence of L’s and D’s to reach 5 could "​LLLDLDL​".
● For the above sequence,
o DiamondPoints(DP) goes from ​0->1->3->​7->7->6->6​->​5​.
o LuckFactor(LF) goes to ​1-> 2-> 4-> -1-> 1-> -1-> 1.
Note:
Though DiamondPoints ​7 and 6 ​are more than ​5​, the game does
not stop because the target is to reach exactly 5.
4 2 ● 4 is the target given
● The shortest sequence of L’s and

KMIT-APA-4008 © ​KMIT-NGIT Page 1 of 4


KMIT – ARJUNA
Season-4
KMIT-APA-4008 Programming Assignments Sunday 29​th​ Sept, 2019

2 Move Metro Pillar Blocks


At a construction site, in Nagole, Hyderabad Metro Rail makes concrete blocks. Every day, from
Nagole, a set of blocks are moved to various sites for assembling them into pillars. The
transport manager’s responsibility is to check and ensure all vehicles have equal load i.e., equal
number of blocks before allowing them to depart from Nagole.

Imagine, there are N transport vehicles parked in a horizontal line and in each of them, the
workers, without bothering about the load, have dumped random number of concrete block(s).
There is one small crane that can shift only one (1) concrete block at a time from one vehicle to
its adjacent vehicle.​ ​It makes several r​ ounds​ of shifting. In one round it can move only one block
to its appropriate vehicle among several vehicles.

Given the number of blocks in each of those N vehicles, the transport manager wants to find
the minimum number of ​rounds​ ​(​not moves​)​ the small crane must make so that all vehicles
have an equal number of blocks in all vehicles. Write a program to help him.

Input/Output
Input Output Comments
204 2 ● 2 0 4 corresponds to three vehicles and number of blocks in each of
them.
● Here are the possible movements from
o Round-1: ​2 0 <-- 4​ => 2 1 3
o Round-2​: ​2 1 <-- 3​ => ​ ​2 2 2
9 14 1 7 ● Here are the possible movements
o Round-1: 9 -->14 --> 1 => 8 14 2
o Round-2: 8 14 --> 2 => 8 13 3
o Round-3: 8 13 --> 3 => 8 12 4
o Round-4: 8 12 --> 4 => 8 11 5
o Round-5: 8 11 --> 5 => 8 10 6
o Round-6: 8 10 --> 6 => 8 9 7
o Round-7: 8 9 --> 7 => ​8 8 8
1351 -1 ● It is impossible to have equal number of blocks in all vehicles.

KMIT-APA-4008 © ​KMIT-NGIT Page 2 of 4


KMIT – ARJUNA
Season-4
KMIT-APA-4008 Programming Assignments Sunday 29​th​ Sept, 2019

3 Minimum Earning Target


Skylight Inc, is a software development company. It has N developers. The company identified ​P
projects each worth ​(V​i​)​ and sets a ​minimum-earning-target​ (MET) i.e., the minimum money to
earn through execution of the projects identified.

Based on the requirements of the projects, the Project Manager ​estimates​ the number of
developers required every project. Every project ​P[i]​ shall have some estimated number of
developers ​D[i].

Here are the challenges for him:


1. Project ​P[i]​ needs at least ​D[i]​ developers to finish it.
2. At a given time, all ​D[i]​ developers must work on any one project only.
3. Single or Multiple teams working on projects must earn at least ​MET
4. He ​cannot hire ​additional developers for those projects. Total developers must be ​N ​only

Now the project manager wants to know the combinations of developer teams that can work
on different projects and reach the ​minimum-earning-target​.

Given the total number of developers (N), ​minimum-earning-target​ (MET), the estimated
number of developers and worth of projects identified, write a program to find the total
number of combinations of possible executions of projects using the estimated number of
developers to make MET. Return 0 if it is not possible to make MET with any of the
combinations.

Input/Output
Input Output Comments
6 6 ● The first line ​6​ represents the total number of developers (N)
40 ● Second line ​40​ represents ​minimum-earning-target​ (MET)
123 ● Third line 1 2 3 represents the estimated number of developers.
30 40 50 ● Fourth line 30 40 50 represents the worth of the projects.
● The estimated number of developers and projects combinations to
earn minimum ​40​ are: ​(2->40), (3->50), (2->40, 3->50), (1->30,
3->50), (1->30, 2->40), (1->30, 2->40, 3->50)
6 0 ● None of the combinations of teams and projects can earn a minimum of ​15
15
231
234

KMIT-APA-4008 © ​KMIT-NGIT Page 3 of 4


KMIT – ARJUNA
Season-4
KMIT-APA-4008 Programming Assignments Sunday 29​th​ Sept, 2019

5 0 ● N=5. MET=5.
5 ● As per estimation, J[0] and J[1] needs 4 and 6 developers. Two projects
46 must be finished to earn MET but the total developers needed are 10
23 (more than 5). Hence, it is not possible to reach MET
10 42
8
1 2 3 2 1 1
1 2 4 4 6 2

KMIT-APA-4008 © ​KMIT-NGIT Page 4 of 4

You might also like