Jugs In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generali…
原题链接 题目大意:有一大一小两个杯子,相互倒水,直到其中一个杯子里剩下特定体积的水.描述这个过程. 解法:因为两个杯子的容积互质,所以只要用小杯子不断往大杯子倒水,大杯子灌满后就清空,大杯子里迟早会出现需要的体积的水.不过也有可能小杯子先剩下符合要求的体积的水. 参考代码: #include<iostream> using namespace std; int main(){ int ca,cb,n,q,r,i; int a,b; while(cin>>ca>>cb&…
ZOJ Problem Set - 1005 Jugs Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gall…
Jugs Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked t…