2016 年青岛网络赛---Tea

2018-06-18 04:15:19来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=5881

 

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
2016 ACM/ICPC Asia Regional Qingdao Online
 

 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5891 5890 5889 5887 5886 
 
题意:输入L,R 表示一壶茶的茶的体积的范围L~R,不确定精确量(整数), 现在往两个茶杯中倒茶(不考虑茶杯容量) ,要求使两个茶杯中茶相差不超过1 ,而茶壶中剩余的茶不能超过1, 求最少倒茶的次数;
        样例解释一下:2 2 答案是1 ,我们可以往第一个茶杯中倒1 ,第二杯不倒, 那么两个茶杯相差为1 ,茶壶剩余量为0~1 , 符合题目要求; 2 4 答案是2 ,我们可以往第一杯倒入1.5  那么第二杯按1.5 到,如果茶壶 茶量为2,那么第二杯倒入0.5 两倍相差1 茶壶为0 符合题目要求,如果茶壶 茶量为4, 第二杯倒入1.5 两杯量相同, 茶壶剩余1, 符合题目要求;
 
思路: 先考虑普通情况,第一杯倒入(L+1)/2, 第二杯按照(L+1)/2+1倒, 那么如果茶壶量为L<=茶壶<=L+2 ,则茶壶为0 了,两杯茶相差0~1 ;如果情况糟糕茶壶不空,那么接下来往第一杯中倒入2 ,第二杯中倒入2 ,第一杯中倒入2 ......知道茶壶不足2 (即茶壶剩余量为0或者1) ,这样两杯茶始终相差1,符合题意;
 
代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <string.h>
using namespace std;

int main()
{
    long long L,R;
    while(scanf("%lld%lld",&L,&R)!=EOF)
    {
        if(L==R)
        {
            if(R<=1) puts("0");
            else if(R==2) puts("1");
            else puts("2");
            continue;
        }
        if(L==0)
        {
            if(R==1) puts("0");
            else if(R==2) puts("1");
            else printf("%lld\n",(R+1)/2);
        }
        else
        {
            if(L==1&&R==2)  puts("1");
            else{
            if(L+2>=R-1) puts("2");
            else printf("%lld\n",(R-L+2)/2);
            }
        }
    }
    return 0;
}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:两种常用的C语言排序算法

下一篇:5-22 龟兔赛跑 (20分)