题目链接:https://cn.vjudge.net/problem/HDU-5881

题意很难理解,就是给你一个茶壶  里面装了水,不知道有多少,装的水 可能是[L, R]区间内的某个值,然后给两个空杯子里倒水,要求两个杯子的水的差的绝对值不超过1,倒完水之后 茶壶里最多剩下不超过1。

分析: 

  1. L==0或者L==1情况等效(因为茶壶内可以留1升水)。
  2. R<=1,茶壶里剩下不超过1,倒0次。
  3. R<=2,茶壶向某一个杯子倒1,两个杯子里茶的差为1,茶壶里剩下不超过1,倒1次。
  4. L==R 或者 L+1==R,从茶壶里分别向两个杯子倒 L/2 。倒2次。
  5. R>L+1,第一次倒给第一个杯子L/2+0.5是最合适的,第二次倒给第二个杯子L/2+0.5+1,再给第一个杯子倒L/2+2.5,再给第二个杯子倒L/2+3.5……这样得到的的公式就是 (R - L) / 2  + 1。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define pb push_back
using namespace std;
const int MAXN = 1010;
const int MAXM = 100100;
const int INF = 0x3f3f3f3f;

int T, n;
int main()
{
    ll L, R;
    while(cin >> L >> R) {
        if(!L) L++;
        if(R <= 1) cout<< 0 <<endl;
        else if(R <= 2)cout<< 1 <<endl;
        else if(L == R || L + 1 == R) cout<< 2 <<endl; 
        else cout<<(R - L) / 2 + 1 <<endl;
    }
    return 0;
}