[ZOJ 1005] Jugs (dfs倒水问题)】的更多相关文章

题目链接: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…
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…
题目链接:https://cn.vjudge.net/contest/281037#problem/A 题目大意:给你a,b,n.a代表第一个杯子的容量,b代表第二个杯子的容量,然后一共有6种操作.让你用尽可能少的步骤将第二个杯子的当前的水的体积转换成n. 具体思路:就是队列模拟啊,,,,打比赛的时候脑子瓦特了,没读完题目就开始读了,,,这个毛病确实得改了,, AC代码: #include<iostream> #include<stack> #include<iomanip&…
ZOJ - 4045District Division 题目大意:给你n个节点的树,然后让你划分这棵数使得,每一块都恰好k个节点并且两两间是连通的,也就是划分成n/k个连通集,如果可以输出YES,并输出对应的划分,否则输出NO 一开始觉得是树形dp,但不知道如何下手,看大佬的做法才恍然大悟,其实就是找子树大小刚好是k的节点,刚让它作为这一分块的根节点,它的父节点就不再记录它的子树大小,详情见代码 #include<cstdio> #include<vector> using nam…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. 给了树的前序遍历序. 直接dfs搜索. #include <cstdio> #include <cstdlib> #include <string> #include <iostream> #include <cstring> #include &…
Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a different type of pipe. There are 11 types of pipes, which is marked…
辗转相减,新手入门题.两个容量的灌水题,无所谓最优解. #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…