三个空瓶可以换一瓶饮料 => 只能喝到1瓶
两个空瓶还可以借一瓶喝了换 => 刚刚好喝到一瓶
最优解就是每次都用两瓶去换...
最后额外附加的方法是模拟过程实现的;
import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; while ((s = br.readLine()) != null) { int bottle = Integer.parseInt(s); if (bottle == 0) { break; } System.out.println(bottle/2); // System.out.println(change(bottle)); } br.close(); } public static int change(int empty) { int drink = 0; while (empty > 3) { drink += empty / 3; empty = empty / 3 + empty % 3; } if (empty == 3 || empty == 2) { return drink + 1; } else { return drink; } } }