You are on page 1of 10

---CSE Question Bank(IIUC)---

https://www.facebook.com/groups/iiucquestionbank/



Spring 2014











Problemset





Allah grant me the serenity
To accept the problems that I cannot solve
The persistence to solve the problems that I can
And the wisdom to know the difference






Organized by: Computer Club
International Islamic University Chittagong
---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem A: Back to Physics

Recently Joule has bought a new heating system to get rid of the chilling cold of winter. The
nights are getting cold and he has started to hit up his heating system for whole night. But, in
the morning, when he gets up from bed, he finds his room as freezing as it used to be. He has
got curious why his system is not able to warm his room. May be it is not producing enough
heat. He has started to think what the formula was for the amount of heat produced by a
heater. He grabbed his old college physics book that he left long ago and in that book he has
got the formula he is looking for. As the formula says, the amount of heat energy

H = I
2
Rt
where,
I = Current flowing through the coil (in ampere)
R = Resistance of the coil (in Ohm)
t = Time (in second)
H = Heat (in Joule)


Input
First line of the input contains the number of test cases. Each of the next line contains a test
case.
A test case consists of three integers I, R and t where 0 I, R, t < 100.

Output
For each test case, output contains an integer on one line denoting the amount of heat
produced by the heating system.

Sample Input Output for Sample Input
5
1 2 3
10 20 30
3 56 51
46 96 10
8 36 44
6
60000
25704
2031360
101376


---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem B: R & D

Nairita rotates the arrow in clockwise direction and notes the direction (e.g. Up,
Down, Left, Right) of the arrow after each rotation. But Eity makes her so busy. Thats why
she can make one rotation in one minute. Nairita feels that to make 100 rotations she needs
lots of time. So, she gives Eity a punishment to make a program which find out the direction
of an arrow after N number of rotation.

For example,
Initially an arrow indicates the right (R), after making 1 rotation in clockwise direction its
rotated direction will be down (D). Now, your job is to write this program for Eity. You have
the initial direction Up (U) / Down (D) / Left (L) / Right (R) and the number of rotation. Find
the rotated direction.



Input
There can be multiple test cases. The first line of input gives you the number of test cases, T
(1 T 100). Then T test cases follow. Each test case consists of a character D from the set
{U, R, L, D} and an integer N (0 N 106) in a single line separating by a space.

Output
Output the rotated direction after N rotation. Each line should contain only one output
character from the set {U, R, L, D} without any leading or trailing space.

Sample Input Output for Sample Input
3
R 8
U 3
U 100
R
L
U


---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem C: LNS

Saif is a student of mathematics. He is excited to announce that he knows a new number
system, which only uses the English Alphabet instead of decimal digits. This is a positional
Number system known as LNS (Letter Number System). It has 26 digits A to Z, which
represents the 0 to 25 decimal numbers respectively. Saif want to make a computer program
to convert decimal number to LNS, but he doesnt have any idea of computer programming.
Now, he asks your help to make a computer program to convert a decimal number to LNS.

For your information, LNS have only 26 letter digits A to Z, which has decimal values of 0
to 25.
For example, 25 converts to Z and 26 converts to BA.

Input
Input consists of several test cases. The first line of the input file contains a single integer
1T1000 indicating the number of test cases. Then T test cases follow. Each test case
contain only a positive integer 0N<2
31
.

Output
For each set of input produce one line of output Case x: LNS, where x indicates the test
case number (starting from 1) and the desired number in LNS.

Sample Input Output for Sample Input
5
26
209
55
646105
100
Case 1: BA
Case 2: IB
Case 3: CD
Case 4: BKTUF
Case 5: DW



---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem D: Childhood Play

John and Mary have been friends since nursery school. Since then, they have shared a playful
routine: every time they meet, they play with a dice and whoever wins has the privilege of
deciding what they are going to play during the day. In a dice throw Mary wins if the dice
comes up with an even number and John wins if the dice comes up with an odd number.

Nowadays they are in college, but continue being truly good friends. Whenever they meet,
they still play dice, and the winner decides which film to watch, or which restaurant to have
dinner together, and so on.

Yesterday Mary confided to John that she has being keeping a record of the results of every
play since they started, in nursery school. It came as a surprise to John! But since John is
studying Computer Science, he decided it was a good opportunity to show Mary his skills in
programming, by writing a program to determine the number of times each of them won the
game over the years.

Input
The input contains several test cases. The first line of a test case contains a single integer N
indicating the number of games played (1 N 10000). The following line contains N
integers R
i
(1 R
i
6), separated by space, describing the list of results. The end of input is
indicated by N = 0.

Output
For each test case in the input your program should output a line containing the sentence
Mary won X times and John won Y times, where X 0 and Y 0.

Sample Input Output for Sample Input
5
2 6 1 4 3
6
6 4 6 2 4 5
0
Mary won 3 times and John won 2 times
Mary won 5 times and John won 1 times


---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem E: Cat and Rat

We have a circular tube. At one point the tube has an entrance.

At time 0, a rat enters the tube via the entrance. The rat can move inside the tube in both
directions (clockwise and counterclockwise). The rat can change direction in an instant. Its
maximum speed is Vrat.

At time T, the cat will enter the tube via the same entrance. The cat can also move in both
directions and change its direction instantly. Its maximum speed is Vcat.

For the purpose of this problem, you should imagine the tube as a circle with radius R, and
the rat and the cat as points on said circle.

The cat is trying to catch the rat as quickly as possible. The rat is trying not to be caught, and
if that is impossible, to be caught as late as possible. At any time (starting at time 0) the cat
and the rat know each other's position. Already at time 0 the rat knows the time T. Assume
that both the cat and the rat behave optimally. The cat and rat cannot leave the tube.

Input
You are given four integers R, T, Vrat, and Vcat. All the values will be between 1 and 1000,
inclusive.

Output
If the cat will catch the rat successfully, print how much time it'll take the cat to catch the rat.
Otherwise, print -1. Print 15 digits after decimal point.

Sample Input Output for Sample Input
10 1 1 1
10 1 1 2
10 1 2 1
1000 1000 1 1000
1 1000 1 2
-1.00000000
1.00000000
-1.00000000
1.00100100
3.14159265


---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem F: Missing Pages

Long ago, there were periodicals called newspapers, and these newspapers were printed on paper,
and people used to read them, and perhaps even share them. One unfortunate thing about this
form of media is that every so often, someone would like an article so much, they would take it
with them, leaving the rest of the newspaper behind for others to enjoy. Unfortunately, because
of the way that paper was folded, not only would the page with that article be gone, so would the
page on the reverse side and also two other pages that were physically on the same sheet of
folded paper.

For this problem we assume the classic approach is used for folding paper to make a booklet that
has a number of pages that is a multiple of four. As an example, a newspaper with 12 pages
would be made of three sheets of paper (see figure below). One sheet would have pages 1 and 12
printed on one side, and pages 2 and 11 printed on the other. Another piece of paper would have
pages 3 and 10 printed on one side and 4 and 9 printed on the other. The third sheet would have
pages 5, 6, 7, and 8.

When one numbered page is taken from the newspaper, the question is what other pages
disappear.

Input
Each test case will be described with two integers N and P, on a line, where 4 N 1000 is a
multiple of four that designates the length of the newspaper in terms of numbered pages, and
1PN is a page that has been taken. The end of the input is designated by a line containing only
the value 0.

Output
For each case, output, in increasing order, the page numbers for the other three pages that will be
missing.

Sample Input Output for Sample Input
12 2
12 9
8 3
0
1 11 12
3 4 10
4 5 6


---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem G: LSB

The digital computer stores the number in binary format. The LSB (Least Significant Bit) is the
bit which indicates the most right bit of a binary number. The decimal 6 stores as 110 and 5
stores as 101 in binary representation. The underline (_) indicates the LSB for 6 and 5. The LSB
of 6 is 0 and 5 is 1. The LSB of 6 is 0 and LSB of 5 is 1. Your task is to find the LSB for positive
integer numbers.

Input
The input file contains one or more sequences of positive integer number. Each sequence starts
with a number N (N < 10
5
) followed by N positive integers x
i
(x
i
< 2
31
). A 0 for N indicates the
end of input.

Output
For each input sequence display the case number (sequentially numbered staring with 1) and LSB
for all numbers in the sequence in sequential order. See the sample for exact format.

Sample Input Output for Sample Input
6 5 6 5 6 5 6
5 9876 78 34 111 77
3 89 76 45
3 89766 1 23
4 676 90 700 211
0
Case 1: 1 0 1 0 1 0
Case 2: 0 0 0 1 1
Case 3: 1 0 1
Case 4: 0 1 1
Case 5: 0 0 0 1


---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem H: Traffic Jam

Now-a-days Traffic Jam became a very big problem in our country. So to solve this problem,
Mr. Khan proposed a model. The proposed model is to make all roads unidirectional means
one way road. Mr. Khan mapped all the cities, but it is very difficult for him to test all the
mapped cities by hand (i.e. by pencil work). Now he needs your help to solve this pencil
work problem using computer program. He said the program will take the map of cities and
will report possible if every place is reachable from every other place otherwise it will
report not possible. For example,








Here, in the given map all the places are represented in decimal values. In the above given
map we can visit every places from place 0 (zero) and finally can also return to place 0
(zero), i.e., 0 -> 1 -> 2 -> 3 -> 0. Similarly it is true for all other places i.e. for place 1, place 2
and place 3. So, the output will be It is possible to visit all the places without quotations. If
from any place we fail to visit all other places then the output will be It is not possible to
visit all the place(s) without quotations.

Input
First line of the input file is an integer t (t<50) which denotes how many sets of maps are
there. Each map will begin with two integers, one denoting number of places (2 p 50) and
in the next line another one denoting number of unidirectional roads between places (1 r
12250). Then followed by individual connections between places x to y, x represents starting
point and y represents destination.

Output
For each line of input produce one line of output. This line contains It is possible to visit all
the places or It is not possible to visit all the place(s) without quotations. See the sample
for exact format.

Sample Input Output for Sample Input
2
4
4
0 1
1 2
2 3
3 0
2
2
0 1
1 2
Case 1: It is possible to visit all the places.
Case 2: It is not possible to visit all the place(s).

0 1
2

3
---CSE Question Bank(IIUC)---
https://www.facebook.com/groups/iiucquestionbank/

P R O G R A M M I N G C O N T E S T S P R I N G 2 0 1 4
Problem I: Fast Flying

Airspeed varies at different heights. So when a plane is flying, it seeks to optimize its time to
reach destination.

You are an Assistant Control Manager (ACM) at Regional Air-traffic Control (RAC). You
are currently assigned to Tomorrows Open Path (TOP) project. So you need to optimize
the path of a flight.

You are given two airports A and B, and the distance D between the two. Planes can fly at H
different heights (excluding the zero height, at which the plane remains before and after
flight). For each kilometer from A to B, you are given time required to fly at H different
heights, T
ih
. You are also given the time required to climb up to the next height, T
U
and climb
down to the previous height, T
D
. If the plane stays at the same height when passing on to the
next kilometer, no climbing delay will occur.

Fig: Example flight from A to B with H = 4 and D = 9.

The plane has to fly. In other words, the plane has to climb up (to some height) at take off and
has to climb down (to zero height) at landing.

Input
There will be at most 10 test cases. Each test case will start with four integers: D, H
(1<D,H<100), T
U
, T
D
. In the next h-th of H lines, there will be D integers; i-th integer is T
ih
.
Input will be terminated by EOF.

Output
For each case, output the minimum time required to fly from A to B. The result will always
lie in [0, 10
6
].

Sample Input Output for Sample Input
10 1 1 2
1 1 1 1 1 1 1 1 1 1
10 2 1 1
2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1
13
14

T
U

T
U

T
U

2T
D

3T
U

2T
D

2T
D

A B
0 1 2 3 4 5 6 7 8 9

You might also like