题意:一壶茶的容量在[L,R]之间,依次倒入两个茶杯中,需要保证最后茶壶中的茶<=1,两个茶杯中的茶相差<=1,问至少需要倒几次?(0<=L<=R<=10^16)
题解:为了保证倒较少的次数,每次倒的要尽可能多,又要让[L,R]中的每个数满足。当L较大时,
若L为奇数,先给第一个人倒,再给第二个人倒+1,接下来第一个人最多只能倒2,第二个人也只能倒2,……,依次下去直到倒完;
若L为偶数,先给第一个人倒+0.5,再给第二个人到+1.5,接下来第一个人最多只能倒2,第二个人也只能倒2,……,依次下去直到倒完。
L=0的情况和R<=2的情况手算一下,其余的情况当L+2+1>=R时,答案为2;否则答案为
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int M=1e9+7;
const int N=1e5+10;
int main()
{
LL L,R;
while (cin>>L>>R){
if (L<=1 && R<=1)cout<<0<<endl;
else if (L==0){
if (R==2)cout<<1<<endl;
else cout<<2+(R-3)/2<<endl;
}
else if (L==1 && R==2)cout<<1<<endl;
else if (L==2 && R==2)cout<<1<<endl;
else if (L+2+1>=R)cout<<2<<endl;
else cout<<2+(R-(L+2))/2<<endl;
}
return 0;
}