编程介的小学生 2017-04-10 08:56 采纳率: 20.5%
浏览 793
已采纳

Paint Mix

Description

You are given two large pails. One of them (known as the black pail) contains B gallons of black paint. The other one (known as the white pail) contains W gallons of white paint. You will go through a number of iterations of pouring paint first from the black pail into the white pail, then from the white pail into the black pail. More specifically, in each iteration you first pour C cups of paint from the black pail into the white pail (and thoroughly mix the paint in the white pail), then pour C cups of paint from the white pail back into the black pail (and thoroughly mix the paint in the black pail). B, W, and C are positive integers; each of B and W is less than or equal to 50, and C < 16 * B (recall that 1 gallon equals 16 cups). The white pail's capacity is at least B+W.

As you perform many successive iterations, the ratio of black paint to white paint in each pail will approach B/W. Although these ratios will never actually be equal to B/W one can ask: how many iterations are needed to make sure that the black-to-white paint ratio in each of the two pails differs from B/W by less than a certain tolerance. We define the tolerance to be 0.00001.
Input

The input consists of a number of lines. Each line contains input for one instance of the problem: three positive integers representing the values for B, W, and C, as described above. The input is terminated with a line where B = W = C = 0.
Output

Print one line of output for each instance. Each line of output will contain one positive integer: the smallest number of iterations required such that the black-to-white paint ratio in each of the two pails differs from B/W by less than the tolerance value.
Sample Input

2 1 1
2 1 4
3 20 7
0 0 0
Sample Output

145
38
66

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试