6.3

来源:互联网 发布:k60单片机百度百科 编辑:程序博客网 时间:2024/05/01 11:30

Topic 6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water(but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly “half” of the jug would be impossible.

// 1) filled 5 quart jug. 2) filled 3 quart with 5 quart’s contents. 3) dumped 3 quart 4) give remainder 2 quart to 3 quart jug. 5) filled 5 quart 6) fill full of 3 quart jug. Done!

// 关键:As long as two jug sizes are relatively prime (have no common prime factors), one can find a pour sequence for any value between one and the sum of the jug sizes.