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 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
 
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\n");
continue;
}
if(r <= 2){
printf("1\n");
continue;
}
if(l == r || l+1 == r){
printf("2\n");
continue;
}
if(l <= 1)
l = 1;
printf("%I64d\n", (r-l)/2+1);
}
return 0;
}

  

HDU 5881 Tea的更多相关文章

  1. hdu 5881 Tea (2016 acm 青岛网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others)    Me ...

  2. HDU 5881 Tea -2016 ICPC 青岛赛区网络赛

    题目链接 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的 ...

  3. HDU 5881 Tea (模拟)

    题意:有一壶水, 体积在 LLL 和 RRR 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水 ...

  4. Tea HDU - 5881

    Tea is good. Tea is life. Tea is everything. The balance of tea is a journey of pursuing balance of ...

  5. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

  6. hdu Hat's Tea

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1288 去买茶,需要正好的钱才行,另外花的钱的个数最多  其实是一个简单的贪心问题,小的多取一点,多的少 ...

  7. HDU 6667 Roundgod and Milk Tea (思维)

    2019 杭电多校 8 1011 题目链接:HDU 6667 比赛链接:2019 Multi-University Training Contest 8 Problem Description Rou ...

  8. HDU 6667 Roundgod and Milk Tea

    hdu题面 Time limit 6000 ms Memory limit 131072 kB OS Windows Source 2019 Multi-University Training Con ...

  9. hdu 1288 Hat's Tea

    这个要慢慢理解…… ;}

随机推荐

  1. 【C++之STL】理解容器(ing)

    “容器可容纳一些数据的模板类” “容器是包容其他对象的对象” 两种类型:顺序容器.关联容器   顺序容器 关联容器 访问成员 顺序访问和随机访问 经过优化关键键值访问                 ...

  2. hdu 4686 Arc of Dream

    思路:构造矩阵 a[i]*b[i]=ax*bx*a[i-1]*b[i-1]+ax*by*a[i-1]+ay*bx*b[i-1]+ay*by 代码如下: #include<iostream> ...

  3. PowerDesigner 逆向工程 从SQL文件转换成PDM 从PDM转成CDM

    从SQL文件逆向工程到PDM: ①选择file -> Reverse Engineer - > Database ②在General选项卡中选择MySQL数据库,点击确定. ③using ...

  4. 小米2s 降到1299

    关于这个价格,网上叫声一片,尤其是几天前刚买了小米2s的,恨死了雷布斯…… 以下是来自百度贴吧的帖子: [02-27 米粉杂谈]我来说个关于价格的事实吧 http://tieba.baidu.com/ ...

  5. 【Linux高频命令专题(14)】nl

    概述 nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样,nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 ...

  6. jquery通过ajax-json访问java后台传递参数,通过request.getParameter获取不到参数的说明

    http://m.blog.csdn.net/blog/eyebrother/36007145 所以当后台通过request.getParameter("name");对参数值的作 ...

  7. 入门视频采集与处理(BT656简介)

    入门视频采集与处理(BT656简介) http://ticktick.blog.51cto.com/823160/553535 1.  帧的概念(Frame) 一个视频序列是由N个帧组成的,采集图像的 ...

  8. Intellij IDEA创建javaWeb以及Servlet简单实现

    1.创建web工程 File --> New --> Project...

  9. 9、JPA_映射双向一对一的关联关系

    双向一对一的关联关系 举例说明:经理Manager和部门Department是双向一对一关联关系.则Manager实体类中有Department实体对象的引用,反之亦然. 其实体属性定义如下: Lis ...

  10. php获取apk包信息的方法

    /*解析安卓apk包中的压缩XML文件,还原和读取XML内容 依赖功能:需要PHP的ZIP包函数支持.*/ include('./Apkparser.php'); $appObj = new Apkp ...