Insomnia Problem Set

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

INSOMNIA ‘08

The Midnight Online Programming Contest

Problem Set

“The Geeks Shall Inherit the Earth”


INSOMNIA ‘08
The
Midnight Online Programming Contest

Rules and regulations


a. Insomnia’08-The Midnight Online Programming Contest, is open only for those students
who are present at IIT Roorkee during the annual technical festival Cognizance‘08.
Please make sure that you have registered for Insomnia.
b. You are free to take the paper with you anywhere inside IITR campus.
c. The solutions will be accepted only through email. The teams are required to email their
solutions from their registered email-id only. Only in case of problem with internet
connectivity solutions will be accepted at Param lab, Institute Computer Center, IIT
Roorkee.
d. Teams should submit the problem solution to the following mail-ids :

Problem Number Mail-id


1, 2 insomnia.id1@gmail.com
3, 4, 5 insomnia.id2@gmail.com

e. The compilers allowed are Dev-Cpp 4.9.9.2 (g++ , gcc) and Turbo 1.0 for C,C++ and
JDK v1.6 for Java only.
f. Teams will be ranked by number of problems solved.
g. In case more than one team solves the same number of problems, they will be ranked by
least total time so the contestants should submit the solution of any problem as soon
as they finish it. Problems can be submitted in any sequence.
h. The time consumed for a solved problem is the time elapsed from the beginning of the
contest to the submittal of the accepted solution plus 15 penalty minutes for every
rejected solution for that problem regardless of submittal time. You can make as many
attempts as desired. We will start accepting solution from 10pm, 29th March onwards,
solutions submitted before that will be considered to be submitted at 10pm.
i. The solution will be evaluated as soon as possible and response will be sent to you.
j. The following types of response will be provided :
 Solution accepted(correct solution)
 Compilation Error(could not be compiled)
 Time out Error(if the program doesn’t terminate in 30 seconds)
 Incorrect solution(If one of more test cases does not yield the desired solution)
k. The total time is the sum of the time consumed for each problem solved. There are no
penalty minutes for rejected solution of a problem whose corrected solution is not
submitted finally.
l. The team must mail their solution source code only and the subject must include problem
number such as “Problem # 4“.
m. The compiler must be specified in body of mail as well as in first line of source code
using comments.
n. The input is to be taken from standard input device i.e. keyboard and the output is sent to
the standard output device i.e. console.
o. The contest ends on 30th March, 2008 at 9am sharp. Any solution sent afterwards will
not be marked.

2
INSOMNIA ‘08
The
Midnight Online Programming Contest

p. Please also send Team members name with contact no. to us in your mail while
submission of problems.
Problem 1
Magic of Rotation
Mathematics is full of numbers with simple and strange properties. Joe a mathematician, once
encountered a number which on right rotation of its digits doubled its value. Fascinated by this fact, he
started a hunt in different mathematical bases (e.g. binary, octal, decimal etc.) for numbers with this
property and realized that there are infinite such type of numbers in any base.
For example in binary number system (base b=2), the numbers 01 and 0101 on right rotation become 10
and 1010 respectively which are the double of their original values. Your task is to find out the smallest
number in a given base which follows this property.

The Input
First line of input will have the number of test cases. Next line will contain the bases b (2<= b <= 499)
each separated by a single space.

The Output
For each base print the smallest such number one per line with digits separated by a space with necessary
leading zeroes. Use decimal representation to print digits in base-b number system.

Sample Input
3
2 7 83

Sample Output
01
035245631421
27 55

3
INSOMNIA ‘08
The
Midnight Online Programming Contest

Problem 2
An Odd Wired Maze
We have an electric circuit with N bulbs and N switches.
B1
The internal arrangement is such that a bulb will glow only
when an odd number of switches connected to it are in ON
position. Given the state of each bulb (Glowing->1, Not- B2
glowing->0) and the connection of switches to bulbs, you
have to determine state of each switch. For example, in the
given circuit the indicated bulb state results when switches B3
states are ON, OFF, OFF, ON (from S1 to S4 in order).

B4
The Input
Each test case begins with an integer N, with 0 < N < 50,
indicating the number of bulbs/switches followed by N
lines. These subsequent lines will contain specifications for each bulb in sequence starting from top (i.e.
from B1 to BN in order). Each of these bulb specification starts with two integers S and P, where S is the
state of the bulb (1 means Glowing, 0 means Not-glowing) and P is the number of switches connected to
that bulb, subsequent integers in that line are the switch numbers that are connected to that specific bulb.
For example
03412
shows that this bulb is not glowing and is connected to 1 st, 2nd and 4th switch. The last test case will be
followed by a 0.

The Output
For each test case print state of each switch (from S1 to SN in order) printing 1 for ON state and 0 for
OFF state (format shown in example below) assuming there is a unique solution.

Sample Input
4
03412
03431
13234
0214

5
145431
03421
143152
042543
1243

Sample Output

4
INSOMNIA ‘08
The
Midnight Online Programming Contest

1001
01010

Problem 3
Confused Counting
In a room there are a number of students either having a red or a black bag. Every student counts the
number of other students having a red bag. Suppose you have the counts provided by all the students.
Your task is to make a program to give the actual number of students having red bags. It’s not for sure that
there count correspond to a valid situation.

The Input
The input consists of a number of test cases. Each test case has a sequence of numbers, kth element of
which is the count reported by kth student. Total number of student is not more than 50.

The Output
For each test case print the actual number of students having red bags. In case given count is not a valid
situation print -1.

Sample Input
112
1121
3333
20 20

Sample Output
2
-1
4
-1

5
INSOMNIA ‘08
The
Midnight Online Programming Contest

Problem 4
Harry Potter and The Pascal’s Triangle
Harry Potter sets up for a new
adventure of finding the
Philosopher’s stone which was held
by Voldemort in a special castle. The
castle resembles the Pascal’s triangle
in such a way that all possible
positions of the stone were at position
of even numbers in a Pascal’s
triangle, while the odd numbers of
the triangle were connected to their
nearest odd neighbors to make the
walls. Some of the walls were thin
(all horizontal lines in the figure,
shown as dash lines) and with his
level of magic Harry could break
only the thin walls.

Your task is to make a program to


find out how many thin walls he
would have to break in order to reach
the stone if he knows the row and the
column of the stone and starts from
the place shown as “H“.
Hint: The problem may require
analyzing Pascal’s triangle deeply!!!

The Input
The first line of input will have the number of test cases followed by lines containing two integers
r (0 <= r <= 255) and c (0 <= c <= r) which are row (position starting from top, topmost is 0) and column
(position in row starting from left, leftmost is 0) of stone respectively.

The Output
For each test case print the minimum number of thin walls to be broken. In case given (r, c) is not a valid
position of stone (i.e. not the position of an even entry in Pascal's triangle), Print "No stone here".

Sample Input
3
41
65
64

Sample Output

6
INSOMNIA ‘08
The
Midnight Online Programming Contest

2
4
No stone here

Problem 5
Catch me if you can!!
There is an electronic rat picker with a long sequence of cages, one after another (in a straight line),
starting from 1, with autoclose doors. As soon as a rat enters the cage 1, all doors start to autoclose. The
closing time of each door is measured in seconds, such that a rat has a fair chance to escape. A cage has
unlimited number of pieces of cheese with same nutritious value. Suppose a rat takes no time to move
from one cage to other but the rat must leave strictly before the moment the door will close if he wishes to
escape. For example if a rat takes t seconds to eat a cheese piece and door will close at t then he should
not eat it (as any cheese piece has to be consumed completely if chosen).

You may note in the following example showing a rat picker with three cages that entrance and exit is
through cage 1 only. You need to return the maximum nutritious value a rat can eat without being trapped
inside the picker.

The Input
Input will have a number of test cases. For each test case first line will have closing time (T1) of doors in
seconds separated by single space. Subsequent lines will have “Nutritious value of one piece of the cheese
type available in that cage (V), Time in eating one piece (T), Cage number (C)” all separated by single
space. A test case ends with three zeroes. (0<T1<2000 0<V, T<1000 0<C<51)

The Output
For each test case print the maximum nutritious value a rat can eat.

Sample Input
7
211
000

11 6 3
111
212
313
000

Sample Output
12

7
INSOMNIA ‘08
The
Midnight Online Programming Contest

17

You might also like