0% found this document useful (0 votes)
109 views12 pages

Overnite Coding Finals

The document describes a card game where each card has a number on the top and bottom, with the top number being points earned and bottom being additional cards that can be played. The player plays cards until they cannot play anymore by choosing cards that maximize points earned over the course of the round. The player is asked to determine the maximum number of points that can be scored given the cards a player has.

Uploaded by

rahul9b71
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views12 pages

Overnite Coding Finals

The document describes a card game where each card has a number on the top and bottom, with the top number being points earned and bottom being additional cards that can be played. The player plays cards until they cannot play anymore by choosing cards that maximize points earned over the course of the round. The player is asked to determine the maximum number of points that can be scored given the cards a player has.

Uploaded by

rahul9b71
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1

OVERNITE CODING FINALS


Rules and Regulations :1. Any kind of discussion with other participants will lead to dis-qualification. 2. Each questions is of a unit mark. 3. For every wrong submission there is a penalty of 20 minutes. The penalty will be applied to the final score only if that particular question gives an Accepted in any of the submissions. 4. The score will come into play only when the number of correct submissions are same.

The House Of Santa Claus


In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you remember that the importance was on drawing the house in a stretch without lifting the pencil and not drawing a line twice? As a reminder it has to look like shown in Figure 1.

Figure 1: The House of Santa Claus Well, a couple of years later, like now, you have to ``draw'' the house again but on the computer. As one possibility is not enough, we require all the possibilities when starting in the lower left corner. Follow the example in Figure 2 while defining your stretch.

Figure 2: This Sequence would give the Outputline 153125432 All the possibilities have to be listed in the outputfile in ascending order, meaning that 1234... is listed before 1235... .

Output
An outputfile could look something like this: 12435123 13245123... 15123421 Arnab Chowdhury

INCL & EXCL


In combinatorics, the inclusionexclusion principle (also known as the sieve principle) is an equation relating the sizes of two sets and their union. It states that if A and B are two (finite) sets, then

Similarly for three sets A,B and C it says that

The General equation then implies that

These mathematical properties that apply on set may be used to solve other problems, like the one below.

Problem Statement
Given n cards(numbered 1-n) and n boxes(numbered 1-n), you need to tell the number of ways in which you can put these numbers, one in each box, such that no box contains the card having the same number as the box in which it is.

Input
The input begins value of T(number of test cases). T lines follow then each containing the value of n .

Output
For each test case output the number of ways in which you can put one card in each box, such that no box has the card with same value as the box number.

Sample Input
3 1 2 3

Sample Output
0 1 2

Boundaries :

1<= n <= 20

compiled by Utsav Barman

Game of Life
Game of Life is a very famous problem in cellular automata. It is a zero player game which means no input is required, just a few rules and then evolution is determined by the initial state and the rules that define the existence. The game is played in a board of dimension NxN. Each live cell is denoted by x and each dead cell is denoted by . The usual rules are described as follows. At each step in time, the following transitions occur: Any live cell with fewer than two live neighbours dies, as if caused by under-population Any live cell with two or three live neighbours lives on to the next generation Any live cell with more than three live neighbours dies, as if by overcrowding Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction This process is continued for M iterations.

Input Specification
The first line contains the number of test cases(T). Each test case consists of a boards initial state (can be of any dimension NxN) followed by number of iterations(M).

Output Specification
For each test case, display the state of the board after M iterations. Followed by a blank line after each test case.

Input Constraints
0 < N <= 20 0 < M <= 100 0 < T <= 100

Sample Input
2 .x....x. xxx. .... 4.x .. 53 Sample Output ......x. ...x.xxx .. .. Swetha T.

MARIO AND HIS GIRL FRIEND


Time Limit : 10 sec

Mario is lost in MARIO World and so is his girlfriend. As everyone knows Marios girlfriend
has been kidnapped. She being the brave one couldnt wait for Mario to complete all the levels and finally get defeated by the BOSS each time and restart from the very beginning. She made a pact with the BOSS that he can keep MARIO as captive and let her free. She now wants to switch positions with Mario. They communicated with each other on mobile and they planned out a strategy so that they can switch position with each other in minimum number of steps (time). t1 step = 1 time unit. A step is defined as a unit movement up, down, left, right or any of the four diagonals. They can not step off the MARIO World. Mario and his girlfriend may not share the same square at the end of a turn. They may not cross paths during a turn. Crossing paths occurs when ario and his girl friend switch positions in a single turn.

PROBLEM STATEMENT
You will be given a 2D matrix representation of the MARIO World you have to find out the minimum number of steps that they will have to take in order to swap their positions (if possible), if not possible output -1 (quotes for clarity). The grid will contain 4 chatacters . , X, A and B. In the matrix, A represents the position of Mario and B represents his girlfriends position. X represents a wall and . is an empty space.

INPUT
First line will contain the dimension of the Mario World MxN (M - number of rows, N number of columns) M lines follow containing N characters. Each test case will be separated by a blank line. There will be maximum of 50 test cases.

OUTPUT
For each test case output will contain only one line, the minimum number of steps required to swap positions (if possible), if not possible output -1.

CONSTRAINTS
44 .... .A.. ..B. .... 3 9 XXXXXXXXX A...X...B XXXXXXXXX 3 9 XXXXXXXXX A.......B XXXXXXXXX 3 9 XXXXXXXXX A.......B XXXX.XXXX MARIO World will contain 2 to 20 elements inclusive Each row will contain 2 to 20 elements inclusive Each row will contain ., X, A or B The grid will contain exactly one A and exactly one B

SAMPLE INPUT

SAMPLE OUTPUT
2 -1 -1 8 Pratyush Verma

PLAY AGAIN
Time Limit: 2 sec

PROBLEM STATEMENT
Gabbar and Thakur are playing Doors Game. This game is played in a building containing a single row of N+1 rooms, numbered 0 through N from left to right. One of the rooms is called the basanti room. There's a door between each pair of adjacent rooms. Each door has a color, and there are 26 possible colors (represented by uppercase letters 'A' through 'Z'). All doors are initially closed.

Initially, Gabbar is in room 0 and Thakur is in room N. The two players alternate turns, and Gabbar gets the first turn. On each turn, the current player chooses a color which hasn't yet been chosen from among the 26 possible colors. All doors, if any, with the chosen color are then opened. At this point, if one of the players can reach the basanti room by walking through only open doors, that player wins and the game ends. If both players can reach the basanti room, the game ends in a draw. If neither player can reach the basanti room, the game continues. Each player wants to win the game in minimum number of colors chosen, if not then in draw or else maximizing the number of colors if he is losing.

INPUT
There will be 'T' test cases. Each test case will contain 2 line having string color pattern in first line and basanti room in second line.

OUTPUT
For each test case you have to print a number. If Gabber wins then print 'X', the number of color chosen. If Thakur wins then print '-X' else(draw) print 0.

SAMPLE INPUT
2 ABCD 2 ABCC 2

SAMPLE OUTPUT
3 -2

CONSTRAINTS
No. of doors will be not greater than 100. basanti room will be between 1 and N-1 inclusive.

EXPLANATION
For case 1, there are 5 doors and basanti is in 2nd room. Gabbar will win the game by choosing 2 colors 'A' and 'B' in two turns, where Thakur can choose only 1 color in his turn. So answer is 3. For case 2, Thakur will win by choosing color 'C' in his turn. So answer is 2. Problem Setter: Nitesh Vishnoi

10

LET'S PLAY
Time Limit: 1 sec

PROBLEM STATEMENT
Gabbar and Thakur like nuts very much. Today they decided to play nut Game. Initially there is a box containing n nuts. Gabbar and Thakur alternate turns, and Gabbar goes first. In each turn, the player must eat some nuts from the box. The number of eaten nuts must be a power of four, i.e., 1, 4, 16, 64 and so on. The first player who cannot eat a valid number of nuts loses. Return the name of the winner assuming that they both play optimally.

INPUT
There will be several test cases. Each test case will contain 1 integer 'n' .

OUTPUT
For each test case you have to print the name of winner.

SAMPLE INPUT
1 2

SAMPLE OUTPUT
GABBAR THAKUR

CONSTRAINTS
n will be between 1 and 1000000000(10^9) Problem Setter: Nitesh Vishnoi

11

COMBINATION
Ravi plays a card game by the following rules. A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number a(i), and the bottom contains number b(i), then when the player is playing the card, he gets a(i) points and also gets the opportunity to play additional b(i) cards. After the playing the card is discarded. More formally: Let's say that there is a counter of the cards that can be played. At the beginning of the round the counter equals one. When a card is played, the counter decreases by one for the played card and increases by the number b(i), which is written at the bottom of the card. Then the played card is discarded. If after that the counter is not equal to zero, the player gets the opportunity to play another card from the remaining cards. The round ends when the counter reaches zero or the player runs out of cards. Of course, Ravi wants to get as many points as possible. Can you determine the maximum number of points he can score provided that you know his cards?

Input
The first line of a test case contains a single integer n (1 <= n <= 10000) the number of cards Ravi has. Each of the next n lines contains two non-negative space-separated integers a(i) and b(i) (0 <= a(i), b(i) <= 200) the numbers, written at the top and the bottom of the i-th card correspondingly. There would be several such test cases in the input file.

Output
Print the maximum number of points Ravi can score in one round by the described rules for each Test case on a separate line.

Sample Input
3 1 2 0 2 1 2 0 0 2 0 0

Sample Output
3 2 Arnab Chowdhury

Breaking Eggs
(Time limit 2 sec )

You have M identical eggs. You want to determine the maximum height that you can drop an egg from a building of N floors without breaking it (or determine if the egg does breaks even

12 when dropped from the first floor). Let us call this maximum safe height the critical height. Our eggs have a unique property: they can withstand one fall from a height greater than the critical height. If the same egg falls from a height greater than the critical height for a second time, it breaks, and it can't be used again.You can use an egg any number of times as long as it is not broken. What is the minimum number of throws you need to determine the critical height in the worst case assuming you follow an optimal strategy?

Input
The first line contains the number of test cases T. Each of the next T lines contains two integers N and M each.

Output
Output T lines, containing the required answer for the corresponding case.

Constraints
1 <= T <= 100000 1 <= N,M <= 30

Sample Input
3 2 1 3 2 5 2

Sample Output:
3 4 5 Explanation: For the first example, N = 2 and M = 1. One strategy is to throw the egg from the first floor twice (note that our special eggs cannot break the very first time you throw it). If the egg breaks, the critical height is 0. Otherwise, throw the egg from second floor twice to determine it's critical height. This requires 4 throws in the worst case. However, there is a better strategy. First throw the egg from floor 2, then from floor 1. If the egg breaks on the second throw, the critical height is 0. If it does not, throw it once again from floor 2 and check if it breaks. This requires just 3 throws in the worst case. Gourav Roy

You might also like