题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
模拟:剩余两瓶就➕一瓶
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); for (int n = in.nextInt(); n != 0; n = in.nextInt()) { int ans = 0; for (;n > 1; n = n / 3 + n % 3 + (n / 3 + n % 3 == 2 ? 1 : 0)) { ans += n / 3; } System.out.println(ans); } } }