Sei sulla pagina 1di 13

Question 1: When text is encoded using Huffman codes, each symbol is replaced by a string of 0s and 1s called a bit string

representation. The replacement is done in such a way that the bit string representation of a symbol is never the prefix of the bit string representation of any other symbol. This property allows us to unambiguously decode the encoded text. You will be given a String archive , a String[] dictionary and number of elements in dictionary. The i-th element of dictionary will be the bit string representation of the i-th uppercase letter. Decode archive using dictionary and print the result as a single String. Test cases : 1. Input : "101101 4 {"00", "10", "01", "11"} Output: "BDC" Because there are no elements in dictionary that are prefixes of other elements, only one element of dictionary will be a prefix of archive. In this case, it is the second element ("10") which represents 'B'. The rest of the text can be decoded using the same logic. 2. Input: "0001001100100111001" 2 {"1","0"} Output: "BBBABBAABBABBAAABBA" '1' is replaced by 'A', '0' is replaced by 'B'. 3. Input: "10111010" 3 {"0","111","10"} Output: "CBAC"

Note that elements of dictionary can be of different lengths. 4. Input: "001101100101100110111101011001011001010" 10 {"110","011","10","0011","00011","111","00010","0010","010","0000"} Output: "DBHABBACAIAIC"

Question 2: There are several skyscrapers arranged in a row. You're interested in finding the one from which the maximal number of other skyscrapers can be seen. The i-th skyscraper can be represented as a line segment on a plane with endpoints (i, 0) and (i, heights[i]) where heights is an array of integers representing the heights of buildings. A skyscraper can be seen from the roof of another skyscraper if a line segment connecting their roofs does not intersect with or touch any other skyscraper. Print the maximal number of other skyscrapers that can be seen from the roof of some skyscraper. You are given total number of skyscrapers. Test cases: 1. Input: 1 {10} Output: 0 There's only a single skyscraper, so you can see no other skyscrapers from its roof.

2. Input: 4
{5,5,5,5} Output: 2 From each skyscraper, you can only see its adjacent neighbors.

3. Input:4
{1,2,7,3,2}

Output: 4 You can see all the skyscrapers from the central one.

4. Input: 15
{1,5,3,2,6,3,2,6,4,2,5,7,3,1,5} Output: 7 You can see 7 skyscrapers form the skyscraper of height 7.

Question 3: The Will Rogers phenomenon is the apparent paradox which occurs when, upon moving an element from one set of numbers to another set, the means (averages) of both sets increase. For example, the sets { 1, 2, 3 } and { 4, 5, 6 } have means 2 and 5, respectively. Moving the 4 to the first set would increase its mean to 2.5, while also increasing the mean of the second set to 5.5. More precisely, we will consider the phenomenon to have occured if, upon moving a number between sets, the mean of both of the sets has strictly increased. An element may be moved from a set only if the set contains at least two elements. You are to move exactly one number from one of the sets to the other. Given the initial configuration of the sets as two arrays, set1 and set2 along with number of elements in each array, print the number of elements which trigger the phenomenon when chosen to be moved. Sample Cases: 1. Input: 3 3 {1,2,3} {4,5,6} Output: 1 This is the example from the problem statement. The number 4 from the second set is the only one which triggers the Rogers phenomenon. 2. Input: 3 4 {3, 100, 90} {5, 1, 18, 29} Output: 0

3. Input: 6 5 {1, 1, 1, 1, 1, 5 } {-10, -9, -8, -7,-6} Output: 5 The sets may contain duplicate elements. Moving any of the 1's from the first set increases the means of both sets.

Question 4: The celebrated general Archibald Waving took charge of the second army in the occidental front. After losing the first army, Waving has become obsessed with effective organization of the army. As a part of this endeavor he has assigned numbers to each of his soldiers. He has also devised a rule which allows two soldiers to work together if and only if the numbers assigned to the soldiers are neighbouring numbers. Two numbers x and y are neighbouring numbers if there exists a permutation of digits of x and a permutation of digits of y such that they are equal if we ignore the leading zeros in the permutations. For example, the numbers 40020 and 204 are neighboring. To see this, permute the digits of 40020 to achieve 00042 and the digits of 204 to achieve 042. If you ignore the leading zeros, both numbers become equal to 42, so they are neighboring. You are given a int[] numbers representing soldiers' numbers. Waving needs to pick two soldiers to send a telegram. He would like to know how many different pairs of soldiers are there who can work together to accomplish the task. Help Waving by printing the number of pairs of neighbouring numbers in the int[] numbers. Examples: 1. Input: 5 {10, 1, 100, 20, 2, 3} Output: 4 The pairs of neighbouring numbers are (10, 1), (1, 100), (20, 2) and (10, 100). 2. Input: 4 {204, 42, 40020, 200} Output: 3

3. Input: 3 {3,33,333} Output: 0 No numbers are neighbours of each other.

Question 5 various wireless access points build up a wireless network. Each access point can support a certain number of computers, and the networks performance increases if the computers are close to the wireless access points supporting them. The strength of the networks is declared by the greatest distance between any computer and its access point. A network has recently been designed that will automatically reconfigure itself every time a computer is added so that the greatest distance will be as small as possible. Your task is to compute, as each computer is added to the network, this distance. Consider the following example: There are 2 access points, at (15,15) and (16,19), each of which can support 2 computers. The first computer to be added to the wireless network is at (13,15). This computer connects to the access point at (15,15), which is only a distance of 2 away. The next computer to be added is at (15,12). This computer also connects to the access point at (5,5), and the greatest distance is now 3. A third computer is added at (14,12). This computer cannot connect to the (15,15) access point because it has already reached its limit. But connecting to (16,19) is not a good choice either because its so far away. Instead, the network reassigns the (13,15) computer to the (16,19) access point so that the new computer can connect to

the (15,15) access point. The greatest distance is now from the (13,15) computer to the (16,19) access point, which is 5. Input Input begins with a line containing 2 integers, A (the number of access points) and C (the number of computers). A+C lines follow. The first A lines contain 3 integers each, giving the coordinates of an access point, followed by the number of connections it can support. The next C lines contain 2 integers each, giving the coordinates of a computer Output In the output the i'th line contains the greatest distance in the network after the first i computers have been added to the network, rounded to 3 decimal places. Sample Input 23 552 692 35 52 42 Sample Output 2.000 3.000 5.000 Constraints T is between 1 and 15, inclusive. A is between 1 and 30, inclusive. Each access point supports between 1 and 30 connections, inclusive. C is between 1 and the total number of supported connections, inclusive. All coordinates comprise integers between 0 and 10000, inclusive. All coordinates are distinct.

Question 6 bob is preparing a Bday cake for Alice, and he decides to write the age of Alice in lighted candles on the cake. There are 10 types of bday candles, one for each digit 0-9. Bob has forgotten the age of Alice, however, so doesnt know whether he has enough bday candles of right types. For example , if alice were 99 years old, Bob would need two 9 candles. Given that Bob has, your work is to let bob know the smallest positive integer that CANNOT be represented with those candles. Input: Input consists of single line with exactly 10 integers, each between 0 and 8, inclusive. The first integer represents the number of '0' candles Bob has, the second integer represents the number of '1' candles the chef has, and so on. Output: Output a single line the smallest positive integer that cannot be expressed with the given candles. Sample input: 2114063222 0111111111 2212113111 Sample output: 4 10 22

Question 7 In a casino there is a very strange machine. If you put C paise in the machine, the remaining money in your wallet will transform in an unusual way. If you have A rupees and B paise remaining in your wallet after depositing the C paise, then after the transformation you will have B rupees and A paise. You can repeat

this procedure as many times as you want unless you don't have enough money for the machine. If at any point C > B and A > 0, then the machine will allow you to break one of the A rupees into 100 paise so you can place C paise in the machine. The machine will not allow you to exchange a rupee for 100 paise if B >= C. Of course, you want to do this to maximize your profit. For example if C=69 and you have 9 rupees and77 paise then after you put 69 paise in the machine you will have 8 rupees and 9 paise (9.77 --> 9.08 --> 8.09). But I should warn you that you can't cheat. If you try to throw away 9 paise before the transformation (in order to obtain 99 rupees and 8 paise after), the machine will sense you are cheating and take away all of your money. You need to know how many times you should do this transformation in order to make a maximum profit. Since you are very busy man, you want to obtain the maximum possible profit in the minimum amount of time. Input Input consists of a single line that contains three nonnegative integers A, B and C where A, B, C < 100. It means that you have A rupees and B paise in your wallet and you need to put C paise in the machine to make the transformation. Output output a single line containing the minimal number of times you should do this transformation in order to make a maximal profit. It is guaranteed that the answer is less than 10000. Example Input:

Ex1: 9 77 69 Ex 2: 98 99 69 Output:

Ex1: 4 Ex2: 0 Explanation In the first example we have the following sequence: 9.77, 8.09, 40.07, 38.39, 70.37, 68.69, 0.68. After last step we have not enough rupees for further transformations. The maximal profit will be after 4 transformations.

Question 8 In order to protect the southern border of ABC Empire against intrusions by various nomadic groups, the Emperor of ABC has decided to build a wall along the southern border. The best architect Brad is recruited for the task. In order to minimize the cost of raw material, Brad is restricted to use only following two kinds of building blocks: X # XX The height of the wall is fixed and is 2 units, but the length of the wall varies. As a part of his job Brad needs to find out the number of ways he can construct the wall using above two types of building blocks where the length of the wall is specified. Write a program to help Brad. Input Format: Input contains an integer N representing the length of the wall. Output Format: Output an integer that represents the number of ways of constructing the wall, modulo 1000000007.

Example: Sample Input: Ex1:

7 Ex2: 2 Ex3: 13

Sample Output: Ex1: 655 Ex2: 5 Ex3: 272767 Constraints: 1<=T<=1000 1<=N<=10^9 Explanation of 2nd Example N=2 The wall can be constructed in following 5 ways: ## ##

X# XX

#X XX

XX X#

XX #X

Potrebbero piacerti anche