Sunteți pe pagina 1din 9

Birla Institute of Technology Mesra, Patna Campus

CODEFREAK
(FINALS)
Time: 75 Minutes (Group) 120 Minutes (Individual)

RULES:
1) The question paper consists of 9 questions. 2) The team solving maximum number of questions will be declared as the winner. 3) In case, the teams draw a tie, the order of preferences are as under: a) Marks obtained in prelims round. b) Team solving the star marked question. c) c codes will be preferred over c++ codes. 4) Any extra paper, electronic gadgets, pen-drives are strictly prohibited. 5) Decision of the judges & coordinators shall be binding and final.

Question 1
There are p red boxes labelled from 0 to p-1. Packets are sent to box 0. The packets get collected in the box 0. But, if at any time, there are more than S packets in a box, a mechanism will occur which will cause 1 packet to move to the immediate next box (if current box is 0, then to box number 1), and all the packets in the current box will vanish and this mechanism continues till no box has number of packets greater than S. Given P,S and the total number of packets A, find the final distribution of packets in the P boxes. Packets are sent one at a time. After one packet is sent, the set of mechanisms, as described, take place. After all mechanisms are over, the next packet is sent. If a particle is going out from the last box, it is lost. Input The input will consist of one line containing three numbers A,S and P separated by spaces. A will be between 0 and 1000000000 inclusive. S will be between 0 and 100 inclusive. P will be between 1 and 100 inclusive. All boxes start off with zero boxes initially. Output Consists of p numbers on one line followed by a newline. The first number is the number of particles in box 0, the second number is the number of packets in box 1 and so on.

Technika12

Example Input: 313 Output: 110 Explanation Total number of 3 packets are sent. After packet 1 is sent, the boxes have packet distribution as "1 0 0". After second packet is sent, number of packets in boxes 0 becomes 2 which is greater than 1. So, number of packets in box 0 becomes 0 and in box 1 becomes 1. So now distribution is "0 1 0". After the 3rd packet is thrown, box 0 gets 1 packet and so distribution is "1 1 0" after all packets are sent one by one.

Question 2
The lecturer of a college is a a bit half mind.. He needs to select the students for the project. But every student seems to be eligible. So to test their knowledge, he finds a stupid idea. The students have to stand in a line in the classroom. They are provided with their respective registration numbers in the order in which they stand, initializing from 1. The captain then removes all the students that are standing at an odd position. Initially, standing students have numbers - 1,2,3,4,5... After first pass, students left are - 2,4,... After second pass - 4,.... And so on. You want to do the project as a team member. Given the total number of applicants for the project, find the best place to stand in the line so that you are selected. Input First line contains the number of test cases p (p<=10^6). The next p lines contain integer n, the number of students for that case(possibility). (n<=10^9) Output Display p lines, each containing a single integer, the place where you would stand to get the project. Example Input: 2 5 12
Output: 4 8

Technika12

Question 3
The main engine of an airoplane failed. So the plane is about to crash. Everyone wants to live.so, there has to be some rescue plan. You are made the incharge of this. You have to make sure that as many people are safe as possible. Given the number of parachutes, that is, the number of people that can be saved, you have to calculate how many men, women and children can saved. The following rules apply: * The foremost priority is safety for children, but there must be atleast one adult (a man or a woman) after every four children.For upto four children, one adult, for five to eight children, 2 adults, and so on. * Next priority is for women, but there must be at least one man after every two women. For upto two women, one man, for three to four women, two men, and so on. Input First line contains the number of test cases (t less than 10000) The next t lines contain four integers (each between 1 to 10000 inclusive) each separated by a single space. The integers represent the number of parachutes, number of men on airoplane, number of women and number of children, in this order. Output Display t lines, each line has three space separated integers denoting the number of men, women and children put to safety, in this order. Example Input: 3 17 5 10 19 18 2 6 10 20 5 2 23 Output: 2 2 13 2 4 10 2 2 16

Technika12

Question 4
There are N students and they are initially served with some chocolates. Some of them are angry because they got less chocolates than some other. Dexter decides to redistribute the chocolates so they all get equal number of chocolates finally. The person distributing the chocolates recollects his friend's code, "Dear, if you ever want to redistribute chocolates, follow this method. While there are two persons with unequal number of chocolates, repeat the following step. Select two persons A and B, A having the maximum and B having the minimum number of chocolates, currently. If there are multiple ways to select A (similarly B), select any one randomly. Let A and B have P and Q number of chocolates respectively and R = ceil( ( P - Q ) / 2 ), Transfer R chocolates from A to B." Given the initial number of chocolates served to each student, find the number of times the person distributing chocolates has to repeat the above step. If he can not distribute chocolates equally by following the above method, print -1. Please note ceil(x) is the smallest integer that is not less than x. Input First line contains an integer T ( number of test cases, around 20 ). T cases follows. Each case starts with an integer N ( 1 <= N <= 3000 ). Next line contains an array A of N integers separated by spaces, the initial number of chocolates served ( 0 <= A[i] <= N ) Output For each case, output the number of times the person distributing chocolates has to repeat the given step to distribute chocolates equally or -1 if its not possible. Example Input: 3 4 1223 2 12 7 1234567 Output: 1 -1 3 Explanation: Case 1 : { 1, 2, 2, 3}. Maximum 3, Minimum 1. R = ceil((3-1)/2) = 1. Transfer 1 chocolates from person having 3 chocolates to the person having 1 chocolates. Each of them has 2 chocolates now, so just 1 step is enough. Case 2 : {1,2} R = ceil((2-1)/2) = 1. {1,2} -> {2,1} -> {1,2} .... they can never get equal chocolates :( Case 3 : Sorted arrays, in the order encountered {1, 2, 3, 4, 5, 6, 7} -> {2, 3, 4, 4, 4, 5, 6} -> {3, 4, 4, 4, 4, 4, 5} -> {4, 4, 4, 4, 4, 4, 4}

Technika12

Question 5
The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime. Input The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each. Output Write a single integer to output, denoting how many integers ti are divisible by k. Example Input: 73 1 51 966369 7 9 999996 11 Output: 4

Technika12

Question 6
Ramu wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example letters "A", "D", "O", "P", "R" divide the plane into two regions so we say these letters each have one hole. Similarly, letter "B" has two holes and letters such as "C", "E", "F", "K" have no holes. We say that the number of holes in the text is equal to the total number of holes in the letters of the text. Help Ramu to determine how many holes are in the text. Input The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input. Output For each test case, output a single line containing the number of holes in the corresponding text. Example Input: 2 CODEFREAK DRINKEATCODE Output: 4 5

Technika12

Question 7
Ramu has a recipe he wishes to use for his guests, but the recipe will make far more food than he can serve to the guests. Ramu therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less food. Ramu, however, does not like fractions. The original recipe contains only whole numbers of ingredients, and Ramu wants the reduced recipe to only contain whole numbers of ingredients as well. Help Ramu determine how much of each ingredient to use in order to make as little food as possible. Input Input will begin with an integer T, the number of test cases. Each test case consists of a single line. The line begins with a positive integer N, the number of ingredients. N integers follow, each indicating the quantity of a particular ingredient that is used. Output For each test case, output exactly N space-separated integers on a line, giving the quantity of each ingredient that Ramu should use in order to make as little food as possible. Sample Input 3 244 3234 4 3 15 9 6 Sample Output 11 234 1532 Constraints T100 2N50 All ingredient quantities are between 1 and 1000, inclusive.

Technika12

Question 8
Consider a string of length N consisting only of lowercase alphabets a-z. Let s[i] be the character at the i-th position in the string (1-based). The string is a K-string if there are EXACTLY K values of i (1 <= i < N) such that s[i+1]<s[i] (we assume 'a'<'b'<'c'<...<'z'). Given K, find the shortest K-string. If there are multiple solutions, find the lexicographically earliest K-string. Input The first line contains the number of test cases T (1<= T <= 100). Each test case contains an integer K ( 100). Output Output T lines, one for each test case, containing the required string. Use only lower-case letters a-z. Sample Input 2 1 2 Sample Output ba cba

Technika12

*****Question 9
Write a program to traverse the spiral path in a given matrix.The input will consist of dimension of aXb matrix a and b, and the elements of the matrix.The output will consist of the numbers encountered while traversing spirally. 1 Exapmle 5 Input a=3 b=4 1 2 3 4 5 6 7 8 9 10 11 12 aXb matrix. 9 6 10 7 11 8 12 2 3 4

Output.. 1 2 3 4 8 12 11 10 9 5 6 7

Technika12

S-ar putea să vă placă și