题目大意:烧脑特辑……
一个茶壶,两个茶杯。
已知当前茶壶里装的茶的体积范围为[L,R]
每次可以往两个茶杯中倒指定量的茶(可为小数),可以比当前茶壶剩余茶多(倒不出来了而已)
要求最终两个茶杯的茶相差的体积
≤1
。(可为小数)
并且茶壶里剩余的茶体积
≤1
问最少需要多少步(在[L,R]范围内所有情况都合法的条件下,最坏情况的步数)
分以下几类:
R≤1:
不倒,都留在茶壶里
0步
R==2:
倒出1杯
1步
L≤1:
第一杯只能1体积-> 0 1
之后
2 1
2 3
4 3
这种两体积两体积的倒
步数
R−12+1
R−L<=2:
第一杯
L2+0.5
第二杯
L2+1.5
步数2
其余情况
第一杯
L2+0.5
第二杯
L2+1.5
之后2体积2体积倒,倒到当前体积较少的杯子里。
但最终可以留1体积在茶壶中,所以可以当成茶体积[L,R-1],然后把茶壶倒空。
步数为
R−L2+1
代码如下:
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
const int maxn = 233;
LL cal(LL l,LL r){
if(r <= 1) return 0;
if(r <= 2) return 1;
if(l <= 1) return (r-1)/2+1;
if(r-l <= 2) return 2;
return 1+(r-l)/2;
}
int main()
{
//fread();
//fwrite();
LL l,r;
while(~scanf("%I64d %I64d",&l,&r)){
printf("%I64d\n",cal(l,r));
}
return 0;
}