解题思路:
1. 循环处理瓶子大于等于3的情况
2. 判断剩余的瓶子数是否为2(其他情况为0或1,不加1),是则加一.
注意事项:
参考代码:
import java.util.Scanner; public class C1072 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); if(n == 0) break; System.out.println(F(n)); } sc.close(); } private static int F(int n){ int count = 0, k = 0; while(n >= 3){ k = n/3; count += k; n = n%3 + k; } if(n == 2) count++; return count; } }
0.0分
0 人评分