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&…
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…
题目链接: D - The Lucky Week ZOJ - 3939 题目大意:幸运的星期指,星期一为每个月的1 or 11 or 21号.给出第一个幸运星期的时间,问从当前的日起开始.第n个的日期. 具体思路:我们通过打表可以发现,每隔400年,当前的这一天的星期和400年后的是相同的.所以我们先求出一个400年有多少个幸运的天数(1600-1999),然后判断当前的年份如果以1600年开始的话,往后n个幸运日是多少,然后再做差以原来的起点输出就可以了. AC代码: #include<bi…
Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A. Input There are multiple…