Sei sulla pagina 1di 7

Sep 1 – Sep3

KNIGHT
CODERS
Instructions
Don't use

#include<iostream.h> and void main()

instead use

#include<iostream>

using namespace std;

int main()

Don’t use

#include <conio.h> and clrscr() and getch().

Remove them before uploading your Code.


Sep 1 – Sep3

Chocolate (PBLM CODE: KNIGHT01)

Little Boy Banku is mad at his teacher, who ate all the sweets in the flat and even went to the
neighbours to eat their sweets too. Now Banku's parents brought home a chocolate bar, and,
sure enough, School teacher is here already and wants to eat it. However, this time Banku has
firmly decided that not a single piece of chocolate will go to this glutton. Banku wants to use
his teacher's addiction to the games of chance and suggests playing the following game. A
chocolate bar can be considered as a rectangle of square “units” arranged in m rows
and n columns and separated by “lines”. Two players take alternate turns. At his turn, a
player must take one piece of chocolate and split it into two along one of the lines. If a player
can't make a legal move (which happens when all pieces of chocolate consist of a single unit
square), he loses, and the winner takes all the chocolate. But the teacher is smart enough! He
immediately understood who should make the first turn in order for teacher to win, assuming
that players take optimal turns. Can you guess that?

Input

First line of input contains number of test cases. The second line of the input contains space-
separated integers m and n (1 <= m, n <= 50).

Output

For each test case If teacher should start the game in order to win, output "[:=[first]"
otherwise, output "[second]=:]".

Example
Input:
3
2 4
1 3
2 9

Output:
[:=[first]
[second]=:]
[:=[first]
Sep 1 – Sep3

3-Ball Story (PBLM CODE: KNIGHT02)

You probably know the game where two players in turns take 1 to 3 balls from a pile. Looses
the one who takes the last ball. We'll generalize this well known game. Assume that both of
the players can take not 1, 2 or 3 balls, but k1, k2, …, km ones. Again we'll be interested in
one question: who wins in the perfect game. It is guaranteed that it is possible to make next
move irrespective to already made moves.

Input

The first line contains number of test cases t <=200. For each test case input is of two lines.
First line contains n and m (1 ≤ n ≤ 10000; 1 ≤ m ≤ 50) — they are an initial amount of balls
in the pile and an amount of numbers k1, …, km. The second line consists of the numbers k1,
…, km, separated with a space (1 ≤ ki ≤ n).

Output

Output 1, if the first player (the first to take balls) wins in a perfect game. Otherwise, output
2.

Example
Input:
2
15 3
3 5 7
17 3
1 4 3

Output:
2
2
Sep 1 – Sep3

Thermometer (PBLM CODE: KNIGHT03)

Jack and Jill were playing with a thermometer once. the thermometer broke when jack failed
to catch it after throwing it up in the air. the children were surprised to see that the spilled
mercury that fell as small round droplets began to merge into bigger droplets.all the more
surprising was that the weight of the bigger droplet was not the same as the sum of the two
little droplets,rather it came out to be 2.sqrt(m1.m2). the children were so anxious to know
that to what limit can the weight of the total mercury decrease. write a program to help them
know it. assume that three or more droplets never merge at once.

Input

The first line contains number of test cases t <=200. The first line of each test case contains
one integer N (1 ≤ N ≤ 100) - the number of mercury balls formed. Each of next N lines
contains one integer ranging from 1 to 10000 - the weight of the corresponding ball.

Output

The output must contain one line with the minimal possible total weight of mercury rounded
to next immediate integer.

Example
Input:
2
3
72
30
50
4
72
35
50
30

Output:
120
125
Sep 1 – Sep3

Neo Training (PBLM CODE: KNIGHT04)

On board the hovercraft Nebuchadnezzar, Neo is practicing his skills for the Matrix. Tank
loads Neo into the Jump program, where he must jump from the the top of one building to the
next. In the Matrix, by concentrating hard Neo can a ect gravity to slow the change in the rate
of his fall to 5 meters/second. As long as Neo does not land, he will continue to move
forward at the same speed he was running before his jump.

Tank can approximate Neo's jump by calculating his speed and position every second. For
example, if Neo jumps up with a speed of 10 meters/second while running at 30
meters/second, the results are:

Time Distance Height Speed


0 seconds 0 meters 0 meters up 10 meters/sec
1 seconds 30 meters 10 meters up 5 meters/sec
2 seconds 60 meters 15 meters up 0 meters/sec
3 seconds 90 meters 15 meters down 5 meters/sec
4 seconds 120 meters 10 meters down 10 meters/sec
5 seconds 150 meters 0 meters down 15 meters/sec

As a result, Neo will jump 150 meters and stay in the air for 5 seconds.
Tank starts testing Neo with jumps to buildings that are at di erent distances away. For
simplicity, Tank will calculate Neo's position at the end of every second, even though more
accurate calculations are possible by if shorter intervals are used.

Input

First line of input consists of the number of test cases t<=1000. For each test case t, the 2nd
line of input consists of a list of three numbers representing a jump to a target building:
1. the speed Neo is running (in meters/second) <=500,
2. the speed Neo jumps up into the air (in meters/second) <=500,
3. the distance to the target building (in meters) <=500.

Output

For each test case Print the distance and height of Neo's jump after each second as a pair of
numbers on a new line, starting at one second. Repeat each second until Neo lands (height
reaches zero or below). Use integers for calculating results. For each building, output "yes" if
Neo is within 3 meters of the building when he lands (height <= zero), else print "no".
Sep 1 – Sep3

Example
Input:
2
30 10 150
10 12 65

Output:
30 10
60 15
90 15
120 10
150 0
yes
10 12
20 19
30 21
40 18
50 10
60 -3
no
Sep 1 – Sep3

Cipher (PBLM CODE: KNIGHT05)

Müller tried to catch Stierlitz red-handed many times, but always failed because Stierlitz
could ever find some excuse. Once Stierlitz was looking through his email messages. At that
moment, Müller entered secretly and watched a meaningless sequence of symbols appear on
the screen. "A cipher message," Müller thought. "UTF-8," Stierlitz thought. It is known that
Stierlitz ciphers messages by the following method. He deletes all spaces and punctuation
marks. He replaces all successive identical letters by one such letter. He inserts two identical
letters at an arbitrary place many times. Try to restore a message as it was after the second
step. For that, remove from the message all pairs of identical letters inserted at the third step.

Input

The first line of input contains number of test cases t<=10000. The next input line for each
test case contains a message ciphered by Stierlitz. The message consists of lowercase English
letters and its length is at most 200000.

Output

Output the restored message

Example
Input:
3
wwstdaadierfflitzzz
ravi maggon
'''hihiiih

Output:
stierlitz
ravimaon
hihih

Potrebbero piacerti anche