五瓶啤酒可以兑换一瓶,三个瓶盖可以兑换一瓶,n个酒瓶可以喝多少次
##考察的递归,跟猴子捞月一样
/**
* @Auther yuan
* @Date 2020/4/26 19:54
* 424048725@qq.com
*/
public class test {
public static void main(String[] args) {
/**
* 五瓶啤酒可以兑换一瓶,三个瓶盖可以兑换一瓶,n个酒瓶可以喝多少次
*/
int i = drinkNum(5, 0, 0);
System.out.println(i);
}
public static int drinkNum(int bottle,int emptyBottle,int cap){
//第一次只有酒瓶
int count1 = bottle;
//酒瓶也是bottle个,可以换bottle/5
int count2 = (bottle+emptyBottle)/5;
int remain2 = (bottle+emptyBottle)%5;
int count3 = (bottle+cap)/3;
int remain3 = (bottle+cap)%3;
if(count2 == 0 && count3 == 0 ){
return count1+count2+count3;
}else{
return count1+drinkNum((count2+count3),remain2,remain3);
}
}
}