Вы находитесь на странице: 1из 16

BASICS: Let’s start from the basics

The Long-form of multiplication of two numbers is a fantastic example of an algorithm which we pick up
right from our childhood without mostly giving a much thought as to why it always seems to work. An
important factor in the success of this amazingly simple looking algorithm is the way we manipulate the
partial products.
Assuming that we do the addition of all the partial products in a single step, your task is to determine
the number of carry-overs in the final sum of the partial products. Refer to following figure to get more
clarity:
1234
x 987 The sum of digits which produce carry-over are:
--------------- 6+7+6 = 19
8638 1+8+8+0 = 17 (note that 1 is carry-over from previous sum of digits)
9872 1+9+1 = 11 (note that 1 is carry-over from previous sum of digits)
11106
---------------
1217958
---------------
As shown in the above figure, the partial products are 8368,9872,11106 and it has 3 carry-overs.
Input Format:
Line 1: N /* the number of test cases (N <=100)*/
Line 2: X1 Y1 /* Test Case 1: X1 Y1 are two numbers to be multiplied. */
Line 3: X2 Y2 /* Test Case 2*/
......
......
Line N+1: XnYn /* Test Case N */
/* the numbers are positive integers can be at the most 100 digits long. */
Output Format:
Line 1: C1 /* C1 is the number of carry-overs in multiplication of X1 and Y1 as explained */
Line 2: C2 /* Carry over for test case 2*/
......
......
Line N: Cn /* Carry Over for test case N */

Sample Input:
3
1234 987
1234 111
1234 929

Sample Output:
3
0
1

TimeLimit:1second(s)
ProblemCode:BASICS
Points: 5

Prime Problem: (PPROB)


Find the number of primes possible which follow the following three conditions:
a) Can be expressed as a sum of squares of two integers x and y (x > y) i.e. x^2 +y^2= prime.
b) Lies between two integers (not necessarily prime numbers) P and Q.
c) Two integers Z and A exists such that (x^y) % Z = A.

Input Format:
Line 1: T // is the no. of test cases; T <= 100
Line 2: P1 Q1 Z1 A1 // Q1 Z1 A1 are the inputs for test case 1
Line 3: P2 Q2 Z2 A2 // Test case 2
....
....
Line 1+T: PtQtZt At // Test case T

Output Format:
Line 1: C1 // Solution for test case 1
....
....
Line T: Ct // Solution for test case T

Sample Input:
2
12 102 7 1
134 194 3 1

Sample Output:
2
5

Limits:
0<=P<100000000
0<Q<=100000000
0<Z<=9999999
0<=A<9999999
TimeLimit:5second(s)
ProblemCode:PPROB
Points: 10

2012 End of The World (ENDOW)


Getting the maps from Charlie, Jackson set to China along with his family. He is on way to the
arks stationed in Tibet, in a van with a Buddhist monk.
They have to reach the destination by choosing among the various paths they have. Also,
because the van can run with its fuel only for a fixed amount of time, they must choose their
paths wisely to move along those edges which lead to some filling stations (that are present at
nodes) if required.
But an earthquake starts in India and is set to destroy their mission to reach the arks.
Given the initial position of the van and assuming the earthquake starts at origin which spreads
evenly in a circular fashion with a fixed increase in radius of destroyed area with time, your task
is to find if they can reach the arks, if yes also the minimum time in which they can do it. Note
also that the time taken at different filling stations is different and once filled, the van can travel
a fixed constant amount of time. Note that it is not possible to fill partly that is they can either
choose to fill completely or not fill at all when passing through the filling stations.
Assume initially the van is filled completely with fuel and do not bother to check whether the
van is getting affected midway by a earthquake in a path from one node to another. Note they
must reach the nodes before the earthquake does or else their mission is a failure.

Input Format:
Number of test cases n ( <= 1000) is the first line of input
Then for each test case
First line contains the x and y coordinates
of van (not origin) at time t=0 separated by a space

Second line has the x and y coordinates of destination separated by a space

Third line contains the time in minutes which the van can run once filled
with fuel

Fourth line contains a floating point number having three precision digits
which indicates the rate of increase in
radius of area affected by earthquake in m per seconds

Fifth line contains a single integer e which indicates total number of edges.

Next e lines contain x1 y1 x2 y2 t


( all the five are integers with edge between
x1,y1 and x2, y2 having the weight t in minutes )

Next line has integer f indicating


number of filling stations followed by f lines each having x y t
(coordinates of filling points followed by time taken
in minutes to fill at this point )

* Consecutive test cases are separated by a blank line.


* Note that all the coordinates and times are non negative integers
given in kilometres and minutes, their absolute value is less than 1001.

Output Format:
For each test case output “yes” if it is possible
to reach the arks followed by another line indicating the minimum time
in which they can reach else output a single line indicating “no”

Sample Input
1
1 1
100 100
30
10.000
6
1 1 2 2 2
2 2 3 3 3
3 3 20 20 10
3 3 60 60 10
20 20 100 100 20
60 60 100 100 12
3
3 3 5
60 60 5
20 20 5

Sample Output:
yes
27
Time Limit: 1 second(s)
Problem Code: ENDOW
Points: 10

Cross Out
Bored by their daily college lectures,one day Saket and Mano decided that they rather better spend
their lecture time playing some ‘geekish’ game, which Saket claimed was one of his novel discoveries.(
Of course he was lying!). So they started playing this game called - ‘Cross Out’.
The rules of the game are as follows:
1. An array of empty boxes is drawn in the rough sheet. (Like the one shown below.) After mutual
agreement between both the players, the total number of boxes that constitute the array is
decided. Let us call it N.
2. The first player starts out by crossing as much number of boxes he wants, but of course he
cannot cross out all the boxes of the array, in the first move of the game, itself.
3. Then the second player has the option to cross as much number of boxes he wants, with the
restriction that at the maximum, he can cross out only twice the number of boxes crossed out in
the previous move by the first player.
4. The game thus continues, with each player crossing out as many boxes he wants. The only
restriction is that he can cross out, at most twice the number of boxes crossed out by the other
player in the previous turn.
5. The one to cross out the last box wins the game.

X X X X X

Saket always insisted on being the first player of the game. Mano always happily agreed, not knowing
why Saket was so adamant being the first to move, when the game seemed to favour the one who
moved second.
However, on the contrary, no matter how many times they played, Mano always lost the game,
notwithstanding Mano always played with most optimum strategy. (Mano is genius, of course.)
This continued, until one day, Mano got frustrated and decided not to play any more until Saket shared
the secret. Saket reluctantly shared the wisdom with Mano and they never played this game again.
(Well, the beauty of magic lies in the trick!)

Well, knowing how much publicity it will fetch, Saket has decided to share half of the wisdom with our
INSOMNIAC friends, too. (Yeah, you guessed it right, he is cunning!)

The wisdom is: ‘The game is won in the first move itself. That is, in the first move of the game you cross
out a given number of boxes and then no matter how much optimally the opponent plays thereafter,
the first player is always going to win. Of course, this does not hold when the first player himself wants
to lose. ’
Never mind, we have assured Saket that there will be many of our talented friends playing out there
today, who can easily see through his cheap trick.

Input Format:
Line 1: T /* number of test cases T<=100 */
Line 2: N1 /* the number of the boxes in the array; 3<N<=1000000; for test case 1*/
.....
.....
Line N+1: Nn /* test case N */

Output Format:
/* Output in each new line the number of boxes that should be crossed out by the first player at start
of the game so that no matter how optimally the game is played thereafter the first player always
wins. */

Line 1: M1 /* Solution for test case 1 */


Line 2: M2 /* Solution for test case 2 */
.....
.....
Line M+N: Mn /* Solution for test case N */

Sample Input:
2
20
220

Sample Output:
2
21
Time Limit: 1 second(s)
Problem Code: CROSSOUT
Points: 15

ULTIMATE GAME

Shashank mostly does coding in his room and if at all he gets bored, plays some flash games.
One day while Shashank was playing a game, Saket entered his room. To make things more
interesting, he set an objective for Shashank.

The game is as follows:


It is played in a rectangular area which is divided into various 1*1 grids (marked using
coordinates from (1,1) to (X, Y) where X and Y are the lengths of its sides) and some of these
grids are blocked. You are given dimensions of a cuboid block (l*h*h where l is length, h is
breadth and h is the height) and it is said to be standing right now if it is currently resting on the
base with minimum area ( the h*h face).

A move is defined as the one which occurs when the cuboid can topple on to any one of its
lateral faces, so anyone of its lateral sides will be the new base after the move is complete.
Also the rotation takes place on the edge common to both lateral face which will become the
new base and the current base. Thus this edge remains in the same position even after rotation.
Observe that there are three possible orientations of the block (obviously if all l, b and h are
different) and in each orientation it can choose from one of the 4 possible moves up, down, left
and right.

An example for 2*1*1 block is given below


Orientations:
Also, consider all possible moves when the block is in standing position:

The objective of the game is to make the cuboid block stand at a provided coordinate position
using legal moves, but Saket asked Shashank to do so in minimum number of moves. The
initial grid of standing is given and sides of its base are parallel to the sides of the rectangular
play area given to you.
Help Shashank!

Input Format:
Line 1: T /* T is the number of test cases T<=100 */
Line 2: X Y /* X Y are dimensions of rectangular board area for test case 1 */
Line 3: L H H /* L,H are integers and < 4. L,H is a non-increasing sequence*/
Line 4: P Q /* (P,Q) indicate the start position of the game. P,Q are integers */
Line 5: G /* G is an integer indicating the number of blocked grids */
Line 6: M1 N1 /* (M1,N1) indicate blocked position of grid 1 */
Line 7: M2 N2 /* (M2,N2) indicate blocked position of grid 2 */
…..
…..
Line 5+G: Mg Ng /* (Mg,Ng) indicate blocked position of grid M */
Line 5+G+1: /* blank space */
Line 5+G+2: X Y /* beginning of test case 2 */
……
……
(/*Note that individual test cases are separated by blank spaces*/)
(/*Note the starting position will that of the grid occupied by the top-left corner of the
specified base of the block */)
Output Format:
Line 1: MV1 /* minimum number of moves in which game can be completed for test case 1*/
Line 2: MV2 /* minimum number of moves in which game can be completed for test case 2*/
……
……
Line N: MVn /* minimum number of moves in which game can be completed for test case N*/

Sample Input:
1
66
211
23
43
3
13
33
44

Sample Output:
4

Pictorial Representation for sample input:


Pictorial representation:
A note about the co-ordinates notation:
The co-ordinates of the block are determined by the co-ordinates of the grid which has the top-
left corner of the base of the block. For example, in the following figure the co-ordinates of the
block are (1,3).

Time Limit: 2 second(s)


Problem Code: ULGAME
Points: 20

Metro Map
With the great success of Delhi Metro, there has been a rise in demand from other metropolitan cities
also, to have a Metro Rail in their city as well. So, we at COGNIZANCE foresee a need for an automated
solution.
Your task is to design an optimal metro rail route through a city, given its map. However, as always, the
economics will be our priority. The map of the city is represented as a matrix:
The following conventions need to be noted:
1) The matrix will have X rows and Y columns.
2) The number in each cell of the matrix denotes the number of colonies that will be get the
benefit, if a metro station were to be placed in that cell of the matrix.
3) There is also a restriction in the minimum number of the colonies that must be covered in this
project.
4) The source station is always located at M (1, 1) and the destination station is always to be
located at M(X, Y).
5) You can establish intermediate stations at different cells in the matrix. However, only one
station can be built at any cell of the matrix.
6) If you choose to establish an intermediate station at M(i,j) then you cannot make the next
stations at following points:
• M(i+1,j)
• M(i,j+1)
• M(p,q) where p < i or q < j (i.e. you cannot make next stations at any backward cells).

Other than the above restrictions, you can make next stations at any other points.
7) Distance between any two stations M(i1,j1) and M(i2,j2) is defined as:
D = sqrt( (i1-i2)2 + (j1-j2)2 )units ( i.e. the Euclidean distance between matrix positions)
8) Two stations will always be connected by rail tracks of length given by the formula in rule 6.
9) The various cost are as follows:
• Cost of a building a station = S
• Cost of laying a unit distance rail track = R.

Your objective is to minimize the following cost of the project given by:

Cost of the project = (S * (Number of stations) + R * (Length of the entire rail track))/ w

Where, w = Total Number of all Colonies that will benefited if metro stations where established in their
respective cells.
And give the route of the Metro Rail from the source to destination for this optimal path.

Input Format:
Line 1: X Y /* X is the number of rows and Y is the number of Columns in matrix;
X<=50 Y<=50 */
Line 2: min_w /* Minimum number of colonies that must be covered */
Line 3: a11 a12 a13 ....... a1Y /* the map of the city as matrix indicating the colonies; 0 <= aij<= 1000
*/
...
...
...
Line 2+X: aX1 aX2 aX3 ....... aXY
Line 3+X: S R /* Cost of building a station & cost of laying unit distance rail track; S<=100000
& R<=100000 */

Output Format:
Line 1: N /* Total number of all stations including source and destination.*/
Line 2: w /* Total number of colonies covered by all of the N stations */
Line 3: i1 j1 /* Route map of M(i,j) positions of N stations in order from source to
destination */
Line 4: i2 j2
....
....
Line 2+N: iNjN
Line 3+N: C /* Optimal Cost of the project;Rounded off to five decimal places. */

Sample Input:
44
15
5374
2892
9475
8622
10 1

Sample Output:
5
23
11
31
33
44
1.97453
TimeLimit:1second(s)
ProblemCode:METROMAP
Points: 30

ALEXANDER
A new continent has just been discovered called Lang. There are already people living on this continent
but they are not governed by anyone. So, all the countries are in a hurry to capture maximum part of
this continent. A country called Prog has just employed you to help it in this mission. You have been
provided with the map of this new continent. All the houses in the Lang have been marked in this map.
This strange continent has only one way roads. These roads are also marked on the map. The only rule
followed in Lang up till now is that a group of houses in which every house is reachable from every other
house, is a village.
• Prog has ordered a brigadier ‘B’ to go to Lang and capture more and more land. For this purpose
he has been allocated a house in some village.
• A village comes under the acquisition of a country only if at least 1 person residing in that village
is a soldier in the army of that country. So, B decides to go house to house to recruit soldiers.
Each village from which he recruits soldier becomes a part of Prog.
• B can visit a house only if he can recruit a soldier from that house. But, a person from a house
(say ‘H’), will become a soldier only if any one of the other houses with direct roads TO ‘H’ has a
soldier. As B is resident of some village so he can start recruiting villagers.
• As B is getting old, he decides to travel each road only once.B can visit each village only once. He
can recruit only one soldier from each house.
• B needs to recruit at least one soldier from each village and move to the next village quickly. ’B’
should capture as many villages as possible.
• Assume that the number of villages is small.
• Assume all roads are of equal lengths.
• Assume that both houses on the ends of the road are different.

Remember, that B can travel each road only once.


Suggest a path to B so that he can capture maximum part of Lang with the minimum number of soldier
recruitments.
First take the input for the first test case. Then give its output as described below. Then take the input
for the next test case and so on.
Assume the maximum number of villages to be 10 and the maximum number of houses in each village
to be 20.
Input-
The name of a house is an alphanumeric string of maximum length 10.
• First line of input should take in the number of test cases.
• Next line of input is the number of houses (n) followed by a space and then the number of
roads(r).
• Next r lines are information on connectivity of roads. One line contains information about one
road. First the name of the house from which road originates is entered followed by a space and
then the name of the house at which the road ends is entered. This road provides connectivity
only from the first house to second house but NOT vice-versa.
• The next line gives the name of the house of B.

Output-
Path
Give the path that B should follow in following format.-
Give the name of each house visited starting from B’s house in each line
Sample
1
9 12
ab
bc
ca
ce
cg
ed
df
fe
fg
gi
ih
hg
a
output-
a
b
c
e
d
f
g

TimeLimit:4second(s)
ProblemCode:ALEX
Points:30
problem code: ARCHI

An architecture student from IIT Roorkee is faced with great problem.

Hari is designing a new hall. He has finalized the coordinates of some statues with base of
dimension (1*1)to be placed in the hall. Now he decides to use tiles of 2*1 dimension for
building the floor.

The tiles must not overlap with one another and should not intrude into places given for the
statues. Also the sides of tiles must be placed parallel to sides of the room. He is not sure
whether he can do the floor building work without cutting any tile in half!!! Since the tiles are
costly he wants to be sure that for the given coordinates of statues, whether it is possible or not
to completely develop the floor using just 2*1 dimension tiles.

The coordinates were marked in the room taking one of the corners as origin.

Input:
Number of test cases n ( <= 100 )is first line of input
Then for each test case the first line contains
dimension of hall (2 <= m, n <= 100)
number of statues t ( <= 100)
The next t lines contain the coordinate of each statue ( x and y separated by space )
This is followed by the rest n-1 test cases separated by blank line

Output:
for each case output a single line having the word "possible" if it is possible to have such a
configuration and "impossible" if it is not possible.

Sample input:
2
44
2
00
30

44
2
00
20
Diagrams for test cases:

Sample output:
possible
impossible

TimeLimit:2second(s)
ProblemCode:ARCHI
Points:30

Вам также может понравиться