22 August 2014

A boy have$Nmoney
in his pocket. The price of each chocolate is$C.
The store offers a discount: for everyM wrappers
he gives to the store, he gets one chocolate for free. How many chocolates does
boy get to eat?

Input Format:
The first line contains the number of test casesT(<=1000).
T lines follow, each of which contains three integers N, C and M

Output Format:
Print the total number of chocolates Boy eats.

Constraints:2≤N≤1051≤C≤N2≤M≤N

Sample Input

3

6 2 2

8 3 4

20 2 2

Sample Output:

5

2

19

Explanations:-

case 1, With 6$, he gets 3 chocolates. So he have 3 wrappers. He exchange 2 wrappers out of 3 to get 4th chocolate and now he have a new wrapper from the 4th chocolate, so total wrappers are 2. He again exchanges them and get 5th chocolate. So answer is 5.

There are N empty
candy jars, numbered from 1 to N, with infinite capacity. M operations are performed. Each
operation is described by 3 integers a, b and k. Here, a and b are index of the jars, and k is the number of candies to be added inside each jar
whose index lies between a and b (both inclusive). Can you tell the average number of
candies after M operations?

Input format

The first
line contains two integers N and M separated
by a single space.

M lines follow. Each of the M lines
contain three integers a, b and k separated
by single space.

Output
Format

A single
line containing the average number of candies across N jars, rounded
down to the nearest integer.

Note

Rounded
down means finding
the greatest integer which is less than or equal to given number. Eg, 13.65 and 13.23 is
rounded down to 13, while 12.98 is rounded down to 12.

20 August 2014

Problem:
There are N number of balls having numbers on them. Number of 1st ball is 0. Number of next ball is either +a or +b then previous ball. Number of next ball is again either +a o +b then previous ball. Find all possible values for last ball(in increasing order) seperated by space
Input is in form of 3 lines
N= no of balls
a
b

Problem:
Given a number like 1234, you need to find number of digits from number which divides the number.
Like 1234 when divided by 1,2,3,4->exact division is by digits 1,2 only, so output should be 2.
Input is in form of T, where T is number of test cases followed by numbers N

Constraints
1<=T<=15
0<N<10000000000

Sample Input:
3
121
123456789
12021

Sample Output:
2
3
2

Explanations:- T = 3, so 3 test cases. For 121, digits are 1,2,1->out of these only 1,1 exactly divides 121, so output is 2.
Solution:

16 August 2014

Problem:
A Palindrome is a string with is exactly same as its reverse string like abcba.
Given a string containing only alphabets from a-z, we have to find minimum number of steps required to convert the string to palindrome.
allowed operations:
- any alphabet can be reduced by 1 lower alphabet in a step like d can be reduced to c
- alphabet a cannot be reduced further

15 August 2014

Problem:
There is a Highway 20 km long. Along the highway, there are 20 service lanes numbered 1-20 and each service lane is 1 km long. Width of service lane can be either 1,2 or 3.
Our data of width is in form of array: 1 2 2 2 3 3 3 1 1 2 2 3 3 3 1 1 2 2 3 3
ie service lane 1 have width 1 and service lane 20 have width 3.
Now a vehicle can exit highway from any service lane and enter highway again from any lane, but we have a width constraint:
-- if width = 1, only bike can enter/exit that service lane.
-- if width = 2, bike or car can enter/exit that service lane.
-- if width = 3, bike, car or truck can enter/exit that service lane.

Input: Entering service lane and exiting service lane
Output: which type of vehicle can pass thru it

Sample Input:
4 6

Sample Output:
Only bike or car can enter by service lane 4 and exit by service lane 6

Explanations:- width of service lane 4,5,6 are 2,3,3--> so truck cannot enter by service lane 4
Solution:

13 August 2014

Problem:
There is a tree (initial height- 1mt) which grows twice its current length in 1st cycle and grows by 1 mt in 2nd cycle and then again twice its current length in 3rd cycle and by 1mt in 4th cycle and so on.
Find the height after Nth cycle.
Input is in form of T and N(i), where T is number of input and N(i) is the cycle number for which height is required.
Also, 0<=T<=10 and 0<=N<=30

Sample Input:
2
0
3

Sample Output:
1
6
Explanations:- T=2, so we need to find height after 0th cycle and after 3rd cycle
Solution:

12 August 2014

Problem:
There are 500 closed doors along a corridor, numbered from 1 to 500. A person walks through the corridor and opens each door. Another person walks through the corridor and closes every alternate door. Continuing in this manner, the i-th person comes and toggles the position of every i-th door starting from door i. You are to determine exactly how many doors are open after the 500-th person has walked through the corridor.

Sample Input:
500

Sample Output:
no of doors opened after 500-th person walked through the corridor having 500 doors is 22
Solution: