You are on page 1of 11

Problem A

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+A

Harry Potter and Magical Spells


It's the beginning of new academic year in Hogwarts School of Witchcraft and Wizardry and Prof. Snape has given Harry a task to analyse magical spells. During this analysis Harry is supposed to find out the number of different letters that are used in a particular spell. Now it's not easy for Harry to keep the record of used letters while counting the number of different letters present in the spell. So now Harry turns to you for help. You being a coder; it's just a matter of few keystrokes for you. Harry will give you a string and your code must print the number of different letters that are used in the given spell. (see sample input/output below for more details)

Input
The first line of input contains an integer T<=500 i.e. the number of test cases. Each of the next T line contains a lowercase word (spell) of not more than 50 letters.

Output
For each test case print the number of unique letters present in that string. Answer each test case in a new line.

Time limit1 second

Sample Input
1 alohomora

Sample Output
6

Explanation
The word alohomora consists of 6 different alphabets i.e. a, l, o, h, m and r. Hence answer is 6.

1 of 1

1/23/2013 8:24 PM

Problem B

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+B

Time travellers
In the world of magic there exist a gate to travel in time. Magical authority has appointed Alice to keep a record of all the people passing through that gate. Every time a person goes inside that gate Alice writes an 'I' in a paper and every time a person comes out of the gate Alice writes down 'O'. Once, magical authority asked Alice about the number of peoples who have used that gate. Now looking at 'I' and 'O' at his paper it's impossible to tell the exact number of peoples who have used that gate but he's sure that there exist a method to know the minimum number of distinct peoples he could have seen passing through the gate. Can you write a code to know the minimum number of peoples he could have seen?

Input
First line of input contains a number T i.e. the number of test cases. Each of the next T lines contains a string S which is the record Alice has kept in his diary.

Output
Your code should print T lines each having one numbers, i.e. the minimum number of peoples he could have seen.

Constraints1<=T<=100 1<=length of S<=1000

Time limit1 second

Sample Input
2 IOIOI OOO

Sample Output
1 3

1 of 1

1/23/2013 8:25 PM

Problem C

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+C

Harry Potter and seven horcruxes


Harry is improving his magical skills day by day and as a result even after partitioning his life into seven horcruxes Lord Voldemort is not feeling safe. Someone in his evil team has suggested him to increase the number of horcruxes hence Voldemort has increased the number of horcruxes. But Harry is not capable of destroying more than 7 horcruxes. Being a talented magician Harry knows it very well how to tackle this situation. Harry can replicate himself. But he exactly dont know how many replications would be required to destroy those horcruxes. Given the number of Horcruxes X your task is to calculate the number of harrys required so as to destroy all horcruxes when each harry can destroy 7 horcruxes.

Input
First line of input is an integer T denoting the number of test cases. Next T line contains an integer X denoting the number of horcruxes Voldemort has.

Output
For each test case, your code should print the minimum number of clones required to destroy X horcruxes. Answer each test case in a new line.

Constraints1<=T<=1000 1<=X<=2000

Time limit1 second

Sample Input
2 78 42

Sample Output
12 6

1 of 1

1/23/2013 8:25 PM

Problem D

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+D

Decisions
Once little piglet plotted the graph of her town. Now she was amazed to know that there exist only one unique path from her house to her college, but there are many points in that path where she has to choose between 2 or more paths. Of course one path goes to the college and other one will lead her to a blocked end. You are given a graph she plotted in the form of a N*M grid. Each cell of the grid is either '.' , '*','M'or 'X'. Where '.' is empty cell and she can walk through it. '*' is the position of her college. 'M' is her house's location and 'X' is the blocked cell which she can't pass. From each cell she can go to any of its 4 neighbouring cell which are not blocked i.e. if she is in (x,y) she can move to (x+1,y),(x-1,y),(x,y-1) or (x,y+1). Now your task is to find the number of decisions she has to make in order to reach college from her house.

Input
First line of input contains a number T i.e. the number of test cases. First line of each test case contains two integers N and M. Next N lines contains a string with only '.', '*', 'M' or 'X' character and length M.

Output
Your code should print T lines each having one numbers, i.e. the number of decisions she has to make in order to reach her college from her house.

Constraints1<=T<=100 1<=N,M<=50

Time limit1 second

Sample Input
2 3 3 ... XMX ..* 2 3 *.M .X.

Sample Output
2 1

1 of 2

1/23/2013 8:25 PM

Problem D

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+D

Explanation
In the first test case, her starting location is (1,1) i.e. row 1 column 1, now from there she can either move to (0,1) or (2,1) so it's the first decision she made. Now when she reached point (2,1) she can either move to (2,2) or (2,0 ) and it's the second decision which she has to make.

2 of 2

1/23/2013 8:25 PM

Problem E

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+E

Hermione and her chocolate love


Hermione loves to add different type of chocolates in her stock. In magical world, different types of chocolate just mean chocolates with different weights. Once, Hermione decided to place all the chocolates with same weight atop each other. Now she wants to know the height of the tower with maximum chocolates and also the number of such towers. As told earlier she's weak in mathematics, can you help her in this task?

Input
First line of input contains a number T i.e. the number of test cases. First line of each test case contain a number N , which is the number of chocolates she has. Next line contains N numbers which are the weights of N chocolates.

Output
Your code should print T lines each having 2 numbers, first number should be the height of the tower with maximum chocolates and second number should be the number of towers.

Constraints1<=T<=100 1<=N<=10000 1<=weight of each chocolate<=30

Time limit2 second

Sample Input
2 3 4 4 2 5 1 3 3 1 2

Sample Output
2 2 2 3

Explanation
Here in the first test case we have 3 chocolates and their weights are 4,4 and 2 so we can make two towers, one of height 2 and one of height 1. Whereas in the second test case we can make 3 towers of height 2, 2 and 1.

1 of 1

1/23/2013 8:26 PM

Problem F

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+F

K-segments
Given an array of N elements. You have to divide it into K consecutive segments according to following rule(a) Suppose array is A[0 . . N] and you have to divide it into K consecutive segments. (b) All the segments are valid if and only if their intersection is NULL and their union is given array. (c) You need to create segments such that maximum of sum of numbers in each segment is minimum. See the first sample test case for better explanation.

Input
First line of input contains an integer T denoting number of test cases. Each test case is composed of 2 lines. First line contains two integers N and K. Next line contains N space separated integers which are the elements of given array.

Output
For each test case just print one integer, that is the answer to given test case. Answer each test case in a new line.

Constraints1<=T<=30 2<=N<=20 2<=K<=N 1<=A[i]<=1000

Time limit1 second

Sample Input
1 9 3 10 20 30 40 50 60 70 80 90

Sample Output
170

Explanation
You can divide the given array A[] into these 3 segments(i) A[0] to A[4] : sum= 150 (ii) A[5] to A[6] : sum= 130 (iii) A[7] to A[8]: sum= 170 Maximum of these sums is 170. There is no other way to choose 3 segments so as to minimize this maximum.

1 of 1

1/23/2013 8:26 PM

Problem G

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+G

Voldemort's Army
Voldemort is training his army of death eaters to finish Harry. To keep the training process easy for himself too, he wants to arrange the death eaters in the increasing order of their strength. Each death eater has some unique positive value of strength. Task is simple, he just need to sort the death eaters in the increasing order of strength. But Voldemort is not aware of any efficient sorting technique. He's using following algorithm in order to complete the task1. He will choose any K consecutive death eaters where K is less than or equal to total number of death eaters. 2. He will then reverse the order of those K death eaters. 3. He will perform above 2 operations until he found all the death eaters arranged in increasing order of their strength. Now this is a time consuming process, so Voldemort is interested in knowing the minimum number of times he has to apply above steps so as to complete the task and if it is impossible to obtain a sorted sequence of death eaters using this technique then simply print -1 .

Input
First line of input contains an integer T denoting number of test cases. First line of each test case contains two numbers N and K. Next line contains N space separated unique integers representing the strength of N death eaters.

Output
Print the minimum number of times he must use his algorithm to arrange death eaters in desired order or -1 if it is impossible to obtain required sequence using given algorithm. Answer each test case in a new line.

Constraints1<=T<=101 2<=N<=8 2<=K<=N 1<=strength<=100

Time limit8 second

Sample Input
2 5 3

1 of 2

1/23/2013 8:26 PM

Problem G

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+G

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

Sample Output
3 -1

2 of 2

1/23/2013 8:26 PM

Problem H

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+H

A magical Chocolate Box


Little piglet is fond of chocolates. Once she bought a box of chocolate which was open from both the ends. There were N chocolates inside the box and there was a different satisfaction factor associated with each of them. Shopkeeper told piglet that satisfaction factor of each chocolate will increase day by day. In simple words suppose the satisfaction factor of a particular chocolate is S on the day piglet purchased the box, and if she eats that chocolate after D days then the amount of satisfaction she'll get from that chocolate is D*S. Piglet decided to eat one chocolate a day. Every day she will have two choices, either she can pull out a chocolate from left end or from the right end. She wants to choose the chocolates in such a way so as to maximize the total satisfaction of the box. She will tell you the current satisfaction factor of each chocolate in the form of an array C where C[i] is the satisfaction factor of ith chocolate. Write a code to find out the total satisfaction that she can get from this box.

Input
First line of input contains a number T i.e. the number of test cases. Each test case contains 2 lines. First lines contains a number N i.e. the number f chocolates in each box. Second line contains N space separated numbers denoting satisfaction factor associated with each chocolate.

Output
Your code should print T lines each having one numbers, i.e. the total satisfaction piglet will get from that chocolate box.

Constraints1<=T<=101 1<=N<=1000 1<=C[i]<=1000

Time limit2 second

Sample Input
1 5 1 5 3 2 4

Sample Output
52

1 of 2

1/23/2013 8:27 PM

Problem H

http://192.168.4.179/~mooshak/cgi-bin/execute/678436515237?view+H

Explanation
Piglet will choose chocolates in following orderC[0]*1+C[4]*2+C[3]*3+C[2]*4+C[1]*5 == 1*1+4*2+2*3+3*4+5*5 == 52

2 of 2

1/23/2013 8:27 PM

You might also like