## 算法问题

2块钱一瓶

4个瓶盖可以换1瓶啤酒

2个瓶子可以换1瓶啤酒

0
Why are you so diao?
0

1. 酒+瓶+盖=2元
2. 盖=0.5元
3. 瓶=1元

0
z

int max_wine_num(int n)
{
int x=((int)n)/2;  //  n块钱换x瓶酒
int round=0;       // 上轮迭代剩余的 瓶+盖 在本轮 能换的瓶数
int y,z;              //  y,z 上轮迭代剩余瓶数和盖数
y=z=0;

int sum=x;  //  sum 能换的最大酒数
do
{
if(sum==x)
{
round=x/2+x/4;
--x;
}
else{
round=y/2+z/4;//本轮 瓶，盖能换的酒数

}

sum+=round;
y=round+y%2;  //本轮能换的酒数+没换掉的瓶数= 本轮剩下的瓶数，留给下一轮换酒
z=round+z%4;  //本轮能换的酒数+没换掉的盖数= 本轮剩下的盖数，留给下一轮换酒
}while(y/2+z/4>0);

return sum;
}

0

def peer(n):
# p1： 买得 p2: 瓶盖 p3：瓶子
p1 = n / 2
total = peer2(p1, p1, p1)
print total

def peer2(total, p22, p33):
if p22 < 4 and p33 < 2:

else:
p2 = p22 / 4
p3 = p33 / 2

total_2 = p2 + p3
total += total_2

p22_list = p22 % 4 + total_2

p33_list = p33 % 2 + total_2

return peer2(total, p22_list, p33_list)

0
```    static int price = 2;
static int pg = 4;
static int pz = 2;
static int beer = 0;
static int ppg = 0;
static int ppz = 0;
public static void getBeer(int money){
beer = ppg = ppz = money/price;
getBeerBypg();
}
static void getBeerBypg(){
beer += ppg/pg;
ppz += ppg/pg;
ppg = ppg%pg;
beer += ppz/pz;
ppg += ppz/pz;
ppz = ppg%pz;

if(ppg>=pg||ppz>=pz){
getBeerBypg();
}

}```

0
c
```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Title</title>
<body>
<input type="text" id="i1" value="10">
<input type="button" onclick="clickOn()">
<h1 id="h1"></h1>
<script>
var a = 1;
function clickOn() {
var n = parseInt(document.getElementById("i1").value);
var b = howMany(Math.floor(n/2), Math.floor(n/2), Math.floor(n/2));
console.log(b);
document.getElementById("h1").innerHTML = b;
}
var howMany = function (num , lastping , lastpinggai) {
if(lastping < 2 && lastpinggai <4){
console.log("return:"+ num);
return num;
}
var lastping1 = Math.floor(lastping/2) + Math.floor(lastpinggai/4) +lastping % 2;
var lastpinggai1 = lastping1 + lastpinggai % 4;
num += lastping1;
console.log(a+":"+num);
a++;
num = howMany(num,lastping1,lastpinggai1);
return num;
}
</script>
</body>
</html>```