思维题——Tea

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 LL.

The exact volume of tea is at most RR.

Alice put two empty cups between you and her.

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

Yours cannot be 11 unit more than hers.

Hers cannot be 11 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 11 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 LL and RR, separated by single space.

Here are some analyses about sample cases.
For the first case, pouring 11 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.51.5 units into one cup, then you attempt to pour another 1.51.5 units into the other cup.
Since the lower bound is 22, at least 0.50.5 unit remains in the pot after the first pouring.
If the initial volume is in range [2,3][2,3], the second cup will have volume in range [0.5,1.5][0.5,1.5] which is balanced with 1.51.5 unit in the first cup, and at most 11 unit remain after these two attempts.

About 10001000 test cases, and 0≤L≤R≤10160≤L≤R≤1016.
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

每次做题被大佬称为水题表示真的很无语。
读题目依然是障碍,但是自己开始学着攻克这个障碍,并且试着去从障碍中获取收获。
真的是xjb想,思路不是我想出来的,简单看下思路然后自己想,只写出来个九九,有一步要考虑的细节准确忽略了。

倒茶要求,两个茶杯最多相差1,茶壶最多剩1。
如果茶壶里最多为1,次数为0;
如果茶壶里最多为2,次数为1;
如果茶壶里大于2,但是至少和至多相差最多为1,则次数为2;
即:茶壶的茶差不离儿为1左右,一杯倒最小量的一半即可。
当茶壶茶可能比较多,并且不确定量较大时,
按最小量的一半倒入一杯,另一杯多到一个单位。
然后每一杯都倒2个单位,直到所有茶都倒完。
列出模型很容易发现特例,即当L=0时,按原来公式第一次倒的单位为0。
重新思考。
说是很容易发现的特例,但我并没有发现。

#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll L,R;
    while(cin>>L>>R){
        if(R<=2){
            if(R<=1)
                cout<<0<<endl;
            else
                cout<<1<<endl;
        }
        else if(L==0){
            cout<<(R-1)/2+1<<endl;
        }
        else{
            if(R<=L+1)
                cout<<2<<endl;
            else
                cout<<(R-L-2)/2+2<<endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值