|
||||||||||
Another Door Repairing ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 263 Accepted Submission(s): 23 Problem Description Maybe you have already solved the Door Repairing Problem for YY, who is the officer of the accommodation building B37, in a famous university called Famous University. Maybe you have not, but it does not matter because the new term is coming. So here comes the Another Door Repairing Problem! As is described in Door Repairing Problem, many students live in B37. The building is old, so sometimes a careless student such as LMY may open the door of the building too vigorously, and break it as a result. However, when a student opens the door and finds it already broken, he will report it to the headmaster, and YY will be punished as a result¡ More precisely, the door is fine at the beginning of the term. The term has a length of Tterm. During the term, the door will be opened many times, which can be regarded as a Poisson process, i.e., in any period of length T, the probability that the door will be opened k times is, where ¦Ë is a positive real constant. Note that for any non-negative real T, When the door is fine and is opened by some student, the probability that he carelessly breaks the door is p. (0<p<=1) When the door is broken, YY can repair it anytime he likes. Both repairing the door and being punished cost a lot. YY has thought for many days trying to make a best strategy when to repair the door, so that his expense can be minimized in expectation. He failed, so he is going to try the simplest ways. Given the length of the term Tterm, the constant ¦Ë, the probability p, and the question type Q, you are to solve the Another Door Repairing Problem: When Q=1, tell the expected number of times YY has to repair the door, if he always repairs it immediately after it is broken. When Q=2, tell the expected number of times YY will be punished, if he never repairs the door. Input Input contains multiple test cases. A test case consists of a single line containing four numbers. The first is an integer Q, where Q=1 or Q=2 holds, indicating the type of the problem that you should solve. Three positive real numbers ¦Ë, Tterm and p follow. The real numbers may be given in fixed-point or scientific e notations. All real numbers can be store in a double data type of C/C++, with a sufficiently small error rate. See the sample input for details. Input ends with a line containing four space-separated 0s. Output For each test case, output one line containing your solution to the specified problem. Your solution should be written in scientific notation: first output a real number, the coefficient part of your solution with two digits after the floating point; then output one space; then output an integer, the exponential part of your solution. You may assume that the absolute value of the exponential part is less than 100. See sample output for details. Sample Input
Sample Output
Hint The solution to sample input is 0.5, 1.0 and 0.213, respectively. Don¡¯t worry about inputting real numbers in scientific e notations. A simple scanf or cin as if it is fixed-point is OK. Source | ||||||||||
|