1005 Jugs】的更多相关文章

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&…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5 题目大意:给你6种操作,3个数a,b,n,代表我有两个杯子,第一个杯子的容量是a,第二个杯子容量是b,问能否通过6种操作,使得第二个杯子里装水量为n dfs搜搜搜!! 状态dfs(x,y) 代表第一个杯子里有水量x,第二个杯子里有水量y. 代码: #include <cstdio> #include <cstdlib> #include <str…
辗转相减,新手入门题.两个容量的灌水题,无所谓最优解. #include<stdio.h> int main(){ int A,B,T,sA,sB; ){ sA=sB=; ){ ){ printf("fill A\n"); sA=A; } else{ printf("pour A B\n"); sB+=sA; if(sB>=B){ if(B!=T){ printf("empty B\n"); sA=sB-B; sB=; } el…
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…
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  1027   Human Gene Functions   简单题  1037   Gridland            简单题  1052   Algernon s Noxious Emissions 简单题  1409   Commun…
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive…
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…
题目链接:https://cn.vjudge.net/contest/281037#problem/A 题目大意:给你a,b,n.a代表第一个杯子的容量,b代表第二个杯子的容量,然后一共有6种操作.让你用尽可能少的步骤将第二个杯子的当前的水的体积转换成n. 具体思路:就是队列模拟啊,,,,打比赛的时候脑子瓦特了,没读完题目就开始读了,,,这个毛病确实得改了,, AC代码: #include<iostream> #include<stack> #include<iomanip&…
http://www.lydsy.com/JudgeOnline/problem.php?id=1005 答案是\[\frac{(n-2)!}{(n-2-sum)!×\prod_{i=1}^{cnt}(d[i]-1)!}×(n-cnt)^{n-2-sum}\] \[sum=\sum_{i=1}^{cnt}(d[i]-1)\] 用到了prufer编码,参考http://www.cnblogs.com/zhj5chengfeng/p/3278557.html 注意要写高精度! #include<cs…