• HDU 5881 Tea


    Tea

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1008    Accepted Submission(s): 286


    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
     
    Source
     
     
     
    解析:题意为有一壶水, 体积在 L 和 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1。你无法测量壶里剩下水的体积, 问最小需要倒水的次数。分析:
    1. R<=1,茶壶里剩下不超过1,不用倒。倒0次。
    2. R<=2,从茶壶里向某一个杯子倒1,两个杯子里茶的差量最大为1,茶壶里剩下的最多为1。倒1次。
    3. L==R或者L+1==R,从茶壶里分别向两个杯子倒 L/2 。倒2次。
    4. L==0或者L==1情况等效(因为茶壶内可以留1升水)。
    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 <cstdio>
    #define ll long long
    
    int main()
    {
        ll l, r;
        while(~scanf("%I64d%I64d", &l, &r)){
            if(r <= 1){
                printf("0
    ");
                continue;
            }
            if(r <= 2){
                printf("1
    ");
                continue;
            }
            if(l == r || l+1 == r){
                printf("2
    ");
                continue;
            }
            if(l <= 1)
                l = 1;
            printf("%I64d
    ", (r-l)/2+1);
        }
        return 0;
    }
    

      

  • 相关阅读:
    HDU 3091 Necklace <<状压dp
    HDU 1074 Doing Homework<<状压dp
    单片机程序设计中的“分层思想”
    单片机的 FIFO循环队列实现
    串口多字节接收
    单片机多字节串口接收(转)
    SD卡应用总结(Fatfs)
    FATFS 初学之 磁盘 I/O接口
    FATFS 初学之 f_gets/ f_putc/ f_puts/ f_printf
    FATFS 初学之 f_chdir/ f_chdrive
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5897685.html
Copyright © 2020-2023  润新知