hdu 5881 Tea (模拟)

2 篇文章 0 订阅

题目链接: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 0≤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

需要注意一些细节,稍微有点磨人的题。场上WA两次。
(话说我一直以为这个思路是贪心诶,大家都说这个是模拟……)

给你一个装着茶的壶和两个空杯子,Alice让你倒茶。

Alice提出以下几个条件:
1.Alice不会告诉你壶里有多少茶,只告诉一个大概的范围:[L,R];
2.一次只能往一个杯子里倒茶,一次倒多少茶你可以精确控制;
3.倒到最后壶里剩下的茶量<=1(虽然你本人不知情,但放心,这个时候Alice会叫你停下);
4.倒到最后两个杯子中的茶量的差的绝对值<=1;
5.倒茶的次数尽量少.

自己分析,分出下列几种情况:

1.R <= 1,这种情况下根本不用倒茶.

2.R <= 2,这种情况下只用倒出量为1的茶即可.

3.R > 2,分两个小情况:

    1.L == 0,此时第一次只能倒量为1的茶,之后交替向两个杯子里倒茶,量为2,
    这是为了防止倒茶过程中茶壶空了的情况,要每时每刻都满足条件4,直到壶中剩下
    量<=1的茶。

    2.其他情况下均可使第一次倒茶量为(L + 1) / 2(结果带有小数),第二次向另
    一个杯中倒茶,量为(L + 1) / 2 + 1,之后交替向两个杯子里倒茶,量为2,原
    因同上,直到壶中剩下量<=1的茶。需要注意的是,一开始倒完最开始那两次可能会
    超过R,这里一定要进行特判。

ac码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <vector>
#include <queue>
#define M 100005

using namespace std;

int main()
{
    long long L, R;
    while(~scanf("%I64d %I64d", &L, &R))
    {
        if(R == 0 || R == 1)    printf("0\n");
        else if(R == 2)     printf("1\n");
        else if(L == 0)     printf("%I64d\n", (R - 1) / 2 + 1);
        else
        {
            if(R - L - 2 > 0)
                printf("%I64d\n", (R - L - 2) / 2 + 2);
            else
                printf("2\n");
        }
    }
    return 0;
}

运行结果:
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值