HDU 5881 乱搞

Tea

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)



Problem Description
Tea is good.

Tea is life.

Tea is everything.

The balance of tea is a journey of pursuing balance of the universe.

Alice knows that.  

Alice wants to teach you the art of pouring tea.

Alice has a pot of tea.

The exact volume of tea is not important.

The exact volume of tea is at least   L .

The exact volume of tea is at most   R .

Alice put two empty cups between you and her.

Alice wants the two cups filled by almost equal volume of tea.

Yours cannot be   1  unit more than hers.

Hers cannot be   1  unit more than yours.

Alice wants you to pour the tea.

Alice wants you to pour until the pot is almost empty.

Alice wants no more than   1  unit volume of tea remaining in the pot.

You cannot read the residue volume of tea remaining in the pot.

You can only know the tea status in the pot, empty or not.

Alice does not want you to pour the tea too many times.

You better pour as few times as possible.
 

Input
There are multiple cases.
For each case, there is one line of two integers   L  and   R , separated by single space.

Here are some analyses about sample cases.
For the first case, pouring   1  unit into one cup will satisfy Alice.
For the second case, it is clearly that you cannot only pour once to reach the desired balance, but she can achieve it by pouring twice.
First you pour   1.5  units into one cup, then you attempt to pour another   1.5  units into the other cup.
Since the lower bound is   2 , at least   0.5  unit remains in the pot after the first pouring.
If the initial volume is in range   [2,3] , the second cup will have volume in range   [0.5,1.5]  which is balanced with   1.5  unit in the first cup, and at most   1  unit remain after these two attempts.

About   1000  test cases, and   0LR1016 .
 

Output
For each case, there should be a single integer in a single line, the least number of pouring attempts.
 

Sample Input
  
  
2 2 2 4
 

Sample Output
  
  
1 2


题意:茶壶里有水,范围在[l,r],现在不知道水多少,只知道倒出来多少,而且没空,现在要倒进两个杯子。

最后满足,两个杯子水量的差值小于等于1,茶壶里的水小于等于1.


题解:

r<=1  不用倒就行了  0次

r<=2  倒一次就行了  1单位 1次

r<=l+3  先在左边倒入l/2,在右边倒入l/2+1  2次

以上为特判


当l<=1时,那就是在左边倒1,然后轮流倒2  茶壶剩1  1+(r-1)/2  (r+1)/2次

否则  先倒l/2  再倒l/2+1  然后轮流倒2  茶壶剩1  2+(r-l-2)/2  (r-l)/2+1次


#include<stdio.h>

__int64 l,r,flag;

int main()
{
    while(~scanf("%I64d%I64d",&l,&r)){
        if(r<=1){printf("0\n");continue;}
        if(r<=2){printf("1\n");continue;}
        if(r<=l+3){printf("2\n");continue;}
        if(l<=1)flag=(r+1)/2;
        else flag=(r-l)/2+1;
        printf("%I64d\n",flag);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值