You are on page 1of 8

Greetings From Globussoft

 Given below are 5 Programming questions, you have to solve any


3 out of 5 questions.

 These 5 questions you can attempt in any technology like C/C++,


java, .Net

 To solve these 5 questions you’ve max. 3 hours.

 While solving these questions you are not allowed to use any
Search Engine like Google, Yahoo, Bing …

All the best for your test

Globussoft
Question: - 1

Solitaire is a game played on an 8x8 chessboard. The rows and columns of the chessboard are
numbered from 1 to 8, from the top to the bottom and from left to right respectively.

There are four identical pieces on the board. In one move it is allowed to:

 move a piece to an empty neighboring field (up, down, left or right),


 jump over one neighboring piece to an empty field (up, down, left or right).

There are 4 moves allowed for each piece in the configuration shown above. As an example let's
consider a piece placed in the row 4, column 4. It can be moved one row up, two rows down, one
column left or two columns right.

Task

Write a program that:

 reads two chessboard configurations from the standard input,


 verifies whether the second one is reachable from the first one in at most 8 moves,

Writes the result to the standard output.


Input

The input begins with the integer t, the number of test cases. Then t test cases follow.

For each test case, each of two input lines contains 8 integers a1, a2, ..., a8 separated by single spaces
and describes one configuration of pieces on the chessboard. Integers a2j-1 and a2j (1 <= j <= 4)
describe the position of one piece - the row number and the column number respectively.

Output

For each test case the output should contain one word for each test case -NO' otherwise.

Example:

Input
1
44455465
24333646

Output
YES

Question: - 2

There are infinitely many coin denominations in the Byteland. They have values of 2^i for i=0,1,2,...
. We will say that set of coins c1,c2,...,ck is perfect when it is possible to pay every amount of money
between 0 and c1+...+ck using some of them (so {4,2,2,1} is perfect while {8,1} is not). The question
is - is it always possible to change given sum n into a perfect set of coins? Of course it is possible ;).
Your task will be more complicated: for a sum n you should find minimal number of coins in its
perfect representation.

Input
First line of input contains one integer c<=50 - number of test cases. Then c lines follow, each of
them consisting of exactly one integer n<=10^1000.
Output

For each test case output minimal number of coins.

Example:

Input
5
507
29
8574
233
149

Output
14
7
21
11
10

Questions: - 3

A manufacturer of sweets has started production of a new type of sweet called rock. Rock comes in
sticks composed of one-centimetre-long segments, some of which are sweet, and the rest are sour.
Before sale, the rock is broken up into smaller pieces by splitting it at the connections of some
segments.

Today's children are very particular about what they eat, and they will only buy a piece of rock if it
contains more sweet segments than sour ones. Try to determine the total length of rock which can
be sold after breaking up the rock in the best possible way.

Input

The input begins with the integer t, the number of test cases. Then t test cases follow.
For each test case, the first line of input contains one integer N - the length of the stick in centimetres
(1<=N<=200). The next line is a sequence of N characters '0' or '1', describing the segments of the
stick from the left end to the right end ('0' denotes a sour segment, '1' - a sweet one).

Output

For each test case output a line with a single integer: the total length of rock that can be sold after
breaking up the rock in the best possible way.

Example:

Input
2
15
100110001010001
16
0010111101100000

Output
9
13

Questions: - 4

On some island each inhabitant is either a knight who only tells the truth, or a liar who always lies.
Also, on the island there exists a university of technology where some of the inhabitants work. All
of the university employees will always tell you the following two things, no matter which employee
you ask:

 There are fewer than N employees who work more than me.
 At least M employees of the university have a larger salary than me.

It is also known that no two employees of the university have an identical salary, and no two work
equally. Write a program which will compute how many persons are employed by this university.
Input

The only input line contains two integers N and M, with one space between them [N, M <=
1000000000].

Output

The output must contain only one integer - the total number of employees of this university, or 0 if
there is no way to find the number of employees.

Example:

Input
11

Output
2

Questions: - 5

Fanatics from the BBFO blew up all the food factories in the Bytelandian capital! Hurry up! There is
still some food left in shops. Some shops are located in the centre, others in the suburbs, so Johnny
has to decide which of them are worth visiting. Some shops can be very big and have plenty of food
in them, others may be so small that food dissappears from them at an alarming rate... So? Help
Johnny buy as much food as possible.

There are n open shops, each of them located at position (xi,yi), for i=1,...,n, where 0 <= xi,yi <= 250.
The distances between shops are measured using the Manhattan metric (i.e. as sums of absolute
values of differences of x and y coordinates). Besides, every shop is characterized by a linear time
function describing how much food is left in the shop at the moment:

fi = max{0, ai - bi * time}

where 0 <= ai <= 1000000, 0 <= bi <= 1000, while time is the time (in minutes) that has elapsed
from the moment Johnny left the house (assume that Johnny does not live in the same place as any
shop). If Johnny decides to stay in a shop, he can buy at most bi units of food per minute. Otherwise,
he can move along the ortogonal system of streets of the city at a constant speed of unit distance
per minute. Johnny only ever changes the action he is performing at the full minute. Because his
family is slowly beginning to starve, he should be back at home not later than m minutes after he
left. Since there are thousands of starving families in the capital, Johnny can't spent more that 1
<= ci <= 10 minutes in a shop. Moreover, he will never go into the same shop twice for fear of being
lynched...

Input
The first line of input contains a single positive integer t <= 1000, the number of test cases. Each test
case begins with the number of shops in the city 1 <= n <= 1000 and the deadline 1 <= m <= 5000.
Then the following n lines consist of four integers xi yi ai bi ci each, describing the position and the
parameters of the function for food availability of the i-th shop. At the end of every test case comes
a line with two integersp q(between 0 and 250), corresponding to the x and y coordinates of the
position of Johnny's house.

All the input data are integers.

Output

Process all test cases. The correct output for the i-th test case takes the following form:

 i [the number of the test case, in the input order]


 s m [s is the number of the target shop and m > 0 is the number of minutes spent in it].
 At the end of the series of moves you should always write a line consisting of two zeros ('0
0').

All the output data should be integers.

Scoring

The score of your program is the total amount of food that Johnny bought (summed over all the
test cases in which he managed to come back home before the deadline).

Example:

Input
4
2 20
0 0 100 5 5
10 0 200 10 10
50
2 20
0 0 180 15 10
10 0 200 20 10
50
4 101
0 0 1000 20 5
20 0 200 1 5
0 20 5000 200 5
20 20 300 5 10
10 10
1 15
1 0 10 1 5
50

Output
1
2 10
00
2
1 10
00
3
35
4 10
21
00
4
15
00

You might also like