Learning Center
Plans & pricing Sign in
Sign Out

Coding.doc - Bytelandian gold coins

VIEWS: 225 PAGES: 15

									                        Bytelandian gold coins

In Byteland they have a very strange monetary system.

Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a
bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have
to make a profit).

You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can
not buy Bytelandian coins.

You have one gold coin. What is the maximum amount of American dollars you can get for it?


The input will contain several test cases (not more than 10). Each testcase is a single line with a
number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.


For each test case output a single line, containing the maximum amount of American dollars you
can make.



You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. If you try
changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more
than $1 out of them. It is better just to change the 2 coin directly into $2.
               Play on Words

Some of the secret doors contain a?very interesting word puzzle. The team of archaeologists has
to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very
important for us.

There is a?large number of magnetic plates on every door. Every plate has one word written on it.
The plates must be arranged into a sequence in such a way that every word begins with the
same letter as the previous word ends. For example, the word ``acm'' can be followed by the
word ``motorola''. Your task is to write a computer program that will read the list of words and
determine whether it is possible to arrange all of the plates in a?sequence (according to the given
rule) and consequently to open the door.


The input consists of T test cases. The number of them (T, equal to about 500) is given on the
first line of the input file. Each test case begins with a line containing a?single integer number N
that indicates the number of plates (1 <= N <= 100000). Then exactly Nlines follow, each
containing a?single word. Each word contains at least two and at most 1000 lowercase
characters, that means only letters 'a' through 'z' will appear in the word. The same word may
appear several times in the list.


Your program has to determine whether it is possible to arrange all the plates in a?sequence
such that the first letter of each word is equal to the last letter of the previous word. All the plates
from the list must be used, each exactly once. The words mentioned several times must be used
that number of times.

If there exists such an ordering of plates, your program should print the?sentence "Ordering is
possible.". Otherwise, output the?sentence "The door cannot be opened.".

Sample input:

Sample output:

The door cannot be opened.
Ordering is possible.
The door cannot be opened.
Warning: large Input/Output data, be careful with certain languages

Rohit dreams he is in a shop with an infinite amount of marbles. He is allowed to select n
marbles. There are marbles of k different colors. From each color there are also infinitely many
marbles. Rohit wants to have at least one marble of each color, but still there are a lot of
possibilities for his selection. In his effort to make a decision he wakes up. Now he asks you how
many possibilities for his selection he would have had. Assume that marbles of equal color can't
be distinguished, and the order of the marbles is irrelevant.


The first line of input contains a number T <= 100 that indicates the number of test cases to
follow. Each test case consists of one line containing n and k, where n is the number of marbles
Rohit selects and k is the number of different colors of the marbles. You can assume that


For each test case print the number of possibilities that Rohit would have had. You can assume
that this number fits into a signed 64 bit integer.

10 10
30 7


Johnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer),
and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an
extremely large number, and would certainly keep Johnny occupied for a while if he were to do it
honestly. But Johnny knows that the teacher will certainly get bored when listening to his answer,
and will sleep through most of it! So, Johnny feels he will get away with reading only the first k
digits of the result before the teacher falls asleep, and then the last k digits when the teacher
wakes up.

Write a program to help Johnny to compute the digits he will need to read out.


The first line contains t, the number of test cases (about 30000). Then t test cases follow.

Each test case consists of one line containing two numbers n and k (1 ≤ n ≤ 109, 1 ≤ k ≤ 9). It is
guaranteed that k is not more than the number of digits of nn.


For each test case, print out one line containing two numbers, separated by a space, which are
the first and the last k digits of nn.

4 2
9 3

25 56
387 489
                             Sums in a Triangle

Let's consider a triangle of numbers in which a number appears in the first line, two numbers
appear in the second line, three in the third line, etc. Develop a program which will compute the
largest of the sums of numbers that appear on the paths starting from the top towards the base,
so that:

       on each path the next number is located on the row below, more precisely either directly
        below or below and one place to the right;
       the number of rows is strictly positive, but less than 100
       all numbers are positive integers between O and 99.


In the first line integer n - the number of test cases (equal to about 1000). Then n test cases
follow. Each test case starts with the number of lines which is followed by their content.


For each test case write the determined value in a separate line.

2 1
1 2 3
1 2
4 1 2
2 3 1 1


Warning: large Input/Output data
     Domain Dilemma
     One of our businesses involves selling domain names. To that effect, we have an online interface
     where potential buyers of domain names can check the availability of domain names, and find out
     how much it is going to cost them.

     Domain tasting is a frowned upon practice in our industry wherein people register domain names
     that are typos of existing domain names in order to make money through displaying ads to the
     traffic received on these typos. For instance if one were to register "" one could
     potentially get traffic from people who were trying to reach "" but instead mis-typed the
     last character.

     In order to disincentivize tasters from registering typos of existing domain names, we wish to levy
     a surcharge on a domain name which is a typo of an existing domain name. The amount of
     surcharge would depend on the type and number of transformations required to convert an
     existing domain to a domain name that someone wishes to register.

     The following type of transformations exist alongwith their cost -

1.           If a transformation requires insertion of one character, it costs 1 point
2.           If a transformation requires deletion of one character, it costs 1 point
3.           If a transformation requires replacement of one character, it costs 2 points, except where
     the character being replaced and its replacement are adjacent to one another on the same line of
     a qwerty keyboard, in which case it costs 1 point

     These operations can be performed in any order, so for example, to transform the domain name
     "directi" to "iriecti", we can either do a deletion of "d" in directi followed by an insertion of "i" or
     perform an insertion followed by the deletion. Similarly, "iriecti" can be transformed to "directi" by
     performing an insertion of "d" followed by a deletion of "i" or vice-versa.

     For all domain name transformations that use 1 or 2 points, we wish to impose a surcharge of 50
     and 25 cents respectively. Any domain name that requires more than 2 points will have no
     surcharge imposed upon them.

     The input starts with a line containing 2 space separated integers m & n followed by a blank line.
     m is the number of already registered domain names. n is the list of names that a customer
     wishes to register - (1 <= m <= 10 6) (1<=n<=10 4). The next m lines are the already registered
     domain names. This is followed by a blank line. The next n lines are the list of names to be
     registered. There will be no space in the domain names, and they will consist only of a
     combination of lowercase alphabets from a to z and digits. The length of a domain name will be
     less than 31 characters.
The output must consist of n lines. You need to print the maximum surcharge incurred for
registering a particular domain when compared with all the already registered domain names plus
the log to the base 10 of the number of domain names that this domain name could be
transformed to by using 1 or 2 points. The value printed should be the integral part of the sum in
case it has a fractional part. If a domain has already been registered, you should output -1.





Monitoring Madness
we have many machines connected to each other since we host many web-sites.
However, administering these machines is a great hassle. That is because a machine can
be administered only by a machine connected directly to it. So, the system administrators
have decided to convert some of the machines in the network to "administrative
machines". However, the cost of converting a machine to an administrative machine is
$100, which is pretty high. So, the system administrators approach you to help them out.

You will be given a list of machines which have a direct connection between them. You
need to display the least cost that the company needs to incur so that every machine in the
final network is administrable by at least one of the machines converted to administrative

For example(the input to your program):


In this case, the least cost you have to incur is $200 and it can be achieved by converting
machines A and B to administrative machines.
Your program will take as an input 'n' coordinates of type {(X1,Y1,Z1),
(X2,Y2,Z2), (X3,Y3,Z3),...(Xn,Yn,Zn)} and from these 'n' coordinates
print a list of 's' coordinates (where 's' is another input parameter
less than 'n') which are closest to the origin (0,0,0) and a list of
't' coordinates (where 't' is another input parameter less than 'n')
points closest to each other. Your solution should use an optimal
strategy and minimal time / space complexity
You are given a plotter which can plot points provided to it in the
form of 'x' and 'y' coordinates. The plotter hand can move horizontally
or vertically only. Your program will be given a list of 'n'
coordinates in the form of {(x1,y1), (x2,y2} ... (xn,yn)}. Your program
must print a sorted list of all 'n' points that would represent the
least cumulative distance for the plotter hand to plot all 'n' points
in that sorted order. If you are feeling adventurous - modify the
program to provide the same output if the plotter can also move
Reaching the Rig
Oil excavation is a common phenomenon in the sea. At every excavation site a rig is
setup to extract the oil. The only mode to reach a rig is by a boat. Men who would like to
reach a rig use special purpose boats which can run on crude fuel available at the rigs and
the shore. These boats can run a mile for every unit of fuel they consume. Each man on
the boat consumes a unit of food for every mile he travels. Boats have a limited load
capacity. The net weight, including the weight of fuel, food and the men, on boat should
never exceed its load capacity. The weight of one unit of fuel is same as the weight of
one unit of food. However, as the rigs are far from the shore in the sea it is usually a very
long sail. The capacity of the boat available for fuel may not be sufficient to reach the
destination rig directly. In such cases, the men may goto a near by rig to load required
fuel. The men can also store food at the rigs as well as at the shore for later consumption.
They must buy all the food they require to reach the destination rig at the shore only. And
all the men who started should be together throughout the sail.

You should now write a program which can help these men decide the minimum amount
of food they require to reach the destination rig. The positions of rigs and the boat's
starting point are indicated as co-ordinates of a two dimensional plane with x and y axises
of 1 mile units. Food at shore is available only in whole units.

Assume that the food and fuel are consumed continuously, that is if you travel a partial
mile the number of units of food and fuel consumed is equal to portion of mile traveled.


The first line of input has a list of integers terminated by -1. The first integer is the
capacity of the boat. The integers following it up to -1 are the weights of men who need
to reach the destination rig.

Lines following will have two integers separated by a space, each line indicating the x
and y coordinates of a coordinate pair respectively. The input will be terminated by a
coordinate pair (0,0) and this should not be processed. The first co-ordinate pair indicates
the position of the boat's starting point. The last coordinate pair indicates the position of
the destination rigs. All other points indicate the position of various rigs in the sea in a
random order.


Your program should print the minimum amount of food required to reach the
destination. If it is not possible to reach destination, then the program should print -1.

Sample Input 1: Sample Input 2:
250 20 30 -1    300 15 20 30 -1   Sample Input 3:
10 -20          10 -20            150 20 30 -1
-10 5           -10 5             11
30 15           30 15             100 100
15 35           -30 45            00
00              00
                                  Output 3:
Output 1:      Output 2:          -1
111            807

One of the cherished customs of my childhood was choosing up sides for a cricket game.
We did it this way: The two bullies of our gully would appoint themselves captains of the
opposing teams, and then they would take turns picking other players. On each round, a
captain would choose the most capable (or, towards the end, the least inept) player from
the pool of remaining candidates, until everyone present had been assigned to one side or
the other. The aim of this ritual was to produce two evenly matched teams and, along the
way, to remind each of us of our precise ranking in the neighbourhood pecking order.

We all believed this was the fairest process, but does it ensure the fairest selection of
players with evenly matched teams? We believed so, but then there were times when, as
the game progressed we realized that the other team was stronger than ours and may be
an exchange of a couple of players between the teams would have made them balanced.
That scope of improvement seemed to be there...

Here, we need to find a way to create two evenly balanced teams for any game(or as
evenly balanced as possible considering the strength of each player). A set of players
must be divided into two teams. Each player must be on one team or the other; the
number of player on the two teams must not differ by more than 1; each player will have
a skill-point associated with him. The total skill-points of the players on each team should
be as nearly equal as possible.(The absolute difference of the sum of skill-points of
players in each team should be the least).


The first line of input will contain the number of test cases 'T'(1<=T<=100). This is
followed by 'T' test cases. Each test case starts with a blank line, followed by N, the total
number of players. N lines will follow with the first line giving the skill-point of person
1; the second line, the skill-point of person 2; and so on. Each skill-point shall be an
integer between 1 and 450. There shall be at most 100 players in all(1<=N<=100).


Your output should be exactly '2T-1' lines. The output for each test case should be
followed by a blank line, except the output for the last test case. Each odd numbered line
should contain 2 numbers: the total skill-points of the players on one team, and the total
skill-points of the players on the other team. Print the smaller sum first.






190 200

27 27

5 13

229 230

To top