版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

倒油问题

有一位厨师要从12斤油(A桶)倒出6斤油但现在手里只有8斤和5斤的桶,怎么取出6斤。

Bucket类

package 搜索.oilTest.common; publicclassBucket {publicint max;//油桶最大容量publicint now;//油桶中的油有多少publicBucket(int max,int now) {this.max = max;this.now = now; }publicintcanIn(){//油桶能倒进多少油return max-now; }publicintcanOut(){//油桶能倒出多少油return now; }publicvoidin(int a){//倒进a now+=a; }publicvoidout(int a){//倒出b now-=a; }@OverridepublicinthashCode() {finalint prime =31;int result =1; result = prime * result + max; result = prime * result + now;return result; }@Overridepublicbooleanequals(Object obj) {if (this == obj)returntrue;if (obj ==null)returnfalse;if (getClass() != obj.getClass())returnfalse; Bucket other = (Bucket) obj;if (max != other.max)returnfalse;if (now != other.now)returnfalse;returntrue; } }

DumpCase类

package 搜索.oilTest.common; import java.util.Arrays; publicclassDumpCase {public Bucket[] buckets =null;public DumpCase parents =null;publicDumpCase(Bucket[] buckets) {this.buckets = buckets; }publicDumpCase(DumpCase u){ buckets=new Bucket[u.buckets.length];for(int i=0;i