茶壺茶量 V ∈ [L, R] (整數區間)。兩茶杯初始為空,需倒茶使:
每次倒茶可指定任意實數量,但無法讀取壺中實際剩余量,只知「空/非空」。
L=2, R=2:倒 1 杯 1 单位,另一杯 0。差值 1,壺剩 0~1。答案 1L=2, R=4:第一杯倒 1.5。若 V=2,壺剩 0.5,第二杯倒 0.5 (差 1);若 V=4,壺剩 2.5,第二杯倒 1.5 (差 0),壺剩 1。答案 2(R+1)/2,答案 (R+1)/2(L+1)/2 和 (L+1)/2 + 1#include <iostream>
#include <cstdio>
using namespace std;
int main() {
long long L, R;
while (scanf("%lld%lld", &L, &R) != EOF) {
if (L == R) {
if (R <= 1) puts("0");
else if (R == 2) puts("1");
else puts("2");
continue;
}
if (L == 0) {
if (R == 1) puts("0");
else if (R == 2) puts("1");
else printf("%lld\n", (R + 1) / 2);
} else {
if (L == 1 && R == 2) puts("1");
else {
if (L + 2 >= R - 1) puts("2");
else printf("%lld\n", (R - L + 2) / 2);
}
}
}
return 0;
}
(L+1)/2 確保下界情況下壺剩 ≤ 1 且杯差 ≤ 1