Algorithm
problem link- https://www.spoj.com/problems/FUNPROB/
FUNPROB - Yanu in Movie theatre
Yanu is a great fan of Harry Potter. So on the day of the movie release, Yanu rushes to the movie theatre to watch the movie. On the release of the 6th movie, on reaching the theatre she found a long queue for tickets already. As the distribution was about to start, the ticket counter did not have any change to start with. There are N+M people in queue, where N have Rs 10.00 and M have Rs 5.00. The ticket costs Rs 5.00.
Now Yanu is math geek too, now she wonders What is the probability that the theatre can always provide change.
Input
Each line contain N and M, separated by a space, End of Input is marked by 0 0 which should not be processed. Both N and M fits in integer range.
Output
For each input, output the respective probability up to 6 decimal digits.
Example
Input:
1 0
0 1
41 41
0 0
Output:
0.000000
1.000000
0.023810
Code Examples
#1 Code Example with Python Programming
Code -
Python Programming
while True:
a, b = map(int, input().split(' '))
if a + b == 0:
break
if a > b:
print ("0.000000")
else:
print("%.6f" %((b - a + 1) / (b + 1)))
Copy The Code &
Try With Live Editor
Input
0 1
41 41
0 0
Output
1.000000
0.023810
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <stdio.h>
int main() {
int m, n;
double mm, nn;
while(scanf("%d %d", &n, &m)==2 && m+n) {
if(!n) printf("1.000000\n");
else if(n > m) printf("0.000000\n");
else {
mm = m; nn = n;
printf("%lf\n", (mm-nn+1.0) / (mm+1.0));
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
0 1
41 41
0 0
Output
1.000000
0.023810
Demonstration
SPOJ Solution-Yanu in Movie theatre-Solution in C, C++, Java, Python