Sei sulla pagina 1di 7

1.

Problem Statement

One day, Professor Prabhjot Singh Kainth(PSK :P) got bored of his powerpuff
girls and decided to create powerpuff boys by using some better chemicals. As
we all know that the powerpuff girls were created using sugar, spice and some
amount of chemical X, so PSK wanted the amounts of sugar and spice to
remain the same, but now he has a lot of options to consider for chemical X.
He has N chemicals available with him numbered 1..N. Every chemical has a
power value associated with it where P[i] represents the power value of the ith
chemical. However, only a limited quantity Q[i] of every chemical is available. If
it were to PSK, he would have chosen all the chemicals available. But he can
carry only a limited quantity of chemicals with him denoted by M. Now he has
to purchase chemicals in such a manner so that they do not cross his carrying
capacity but at the same time they also allow him to create the most powerful
powerpuff boys.

Input Format
First line contains t denoting the number of test cases (1 <= t <= 5) The next
line contains 2 integers N and M where N denotes the number of chemicals
available and M denotes the available budget with PSK The next N lines
contains 2 integers each Q[i],P[i] where Q[i] denotes the quantity available per
chemical, P[i] denotes the power of each chemical.

Output Format
Output in a single line the maximum power that can be attained using these
set of chemicals.Print your answer upto 6 decimal places

Sample Input
1
3 40
50 60
40 258
700 700

Sample Output
258.000000

2. Problem Statement
Write a program that finds all occurrences of a given pattern in a given input
string. This is often referred to as finding a needle in a haystack.
The program has to detect all occurrences of the needle in the haystack. It
should take the needle and the haystack as input, and output the positions of
each occurrence, as shown below.

Input Format
The input consists of a number of test cases. Each test case is composed of
three lines, containing:

the length of the needle,


the needle itself,
the haystack.

The test cases come one after another, each occupying three lines, with no
additional space or line breaks in between.

Output Format
For each test case your program should output all positions of the needle's
occurences within the haystack. If a match is found, the output should contain
the position of the first character of the match. Characters in the haystack are
numbered starting with zero.
For a given test case, the positions output should be sorted in ascending
order, and each of these should be printed in a separate line. For two different
test cases, the positions should be separated by an empty line.

Sample Input
3

na

banananobano

foobar

foo

foobarfoo

barfoobarfoobarfoobarfoobarfoo

Sample Output

4
3

15

21

Note the double empty line in the output, which means that no match was
found for the second test case.

3. Problem Statement
Chef has bought N robots to transport cakes for a large community wedding.
He has assigned unique indices, from 1 to N, to each of them. How it will
happen?
Chef arranges the N robots in a row, in the (increasing) order of their indices.
Then, he chooses the first M robots and moves them to the end of the queue.
Now, Chef goes to the robot at the first position in the row and hands it one
cake. He then notes this robot's index (say k) in his notebook, and goes to the
kth position in the row. If the robot at this position does not have a cake, he give
him one cake, notes his index in his notebook, and continues the same process.
If a robot visited by Chef already has a cake with it, then he stops moving and
the cake assignment process is stopped.
Chef will be satisfied if all robots have a cake in the end. In order to prepare the
kitchen staff for Chef's wrath (or happiness :) ), you must find out if he will be
satisfied or not? If not, you have to find out how much robots have a cake, so
that the kitchen staff can prepare themselves accordingly.

Input Format
The first line of input contains a single integer T denoting the number of
test cases.
The single line of each test cases contains two space separated
integers N and M.

Output Format
For each of the T test cases, output a single line:
If all N robots have a cake, output "Yes" (without quotes).

Otherwise, output "No" (without quotes) followed by a space and


the number of robots which have a cake.

Sample Input
3
20
21
42

Sample Output
No 1
Yes
No 2

4. Problem Statement
Given arrival and departure times of all trains that reach a railway station, find
the minimum number of platforms required for the railway station so that no
train waits.

Input Format
The first line contains an integer n representing the total number of trains.
The second line contains n integers representing the arrival time of the n
trains.

The third line contains n integers where the ith integer corresponds to the
departure time of the train whose arrival time was the ith integer in the
second line.

Output Format
A single integer representing the minimum number of platforms.

Sample Input
6

900 940 950 1100 1500 1800

910 1200 1120 1130 1900 2000

Sample Output
3

5. Problem Statement
Every positive fraction can be represented as sum of unique unit fractions. A
fraction is unit fraction if numerator is 1 and denominator is a positive integer,
for example 1/3 is a unit fraction. Such a representation is called Egyptian
Fraction as it was used by ancient Egyptians. Given a fraction find its Egyptian
Fraction representation.

Input Format
The first line consists of two integers, nr and dr representing the numerator
and denominator respectively.

Output Format
Print the Egyptian Fraction Representation on nr/dr.

Sample Input
23

Sample Output
1/2+1/6

Potrebbero piacerti anche