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. hdu1301Jungle Roads

    http://acm.hdu.edu.cn/showproblem.php?pid=1301 最小生成树模板题 #include<iostream> #include<stdio.h ...

  2. Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException

    在线程中出现这种错误的原因是多次启动start() 解决方法: 将start()改成 run()

  3. lintcode :Segmemt Tree Build II

    题目 Segmemt Tree Build II The structure of Segment Tree is a binary tree which each node has two attr ...

  4. lintcode :链表插入排序

    题目: 链表插入排序 用插入排序对链表排序 样例 Given 1->3->2->0->null, return 0->1->2->3->null 解题: ...

  5. 2014-9-17二班----9 web project

    http://localhost:8080/rwkj1/indexServlet             跳转                    http://localhost:8080/rwk ...

  6. Altium Designer哪里下载和导入元件库_图文教程

    http://jingyan.baidu.com/article/46650658064621f549e5f88f.html

  7. 【C#设计模式——创建型模式】工场方法模式

    工场方法模式对简单工场模式进行了乔庙的扩展,不是用一个专门的类来决定实例化哪一个子类.相反,超类把这种决定延迟到每个子类.这种模式实际上没有决策点,就是没有直接选择一个子类实例化的决策. 看书上的例子 ...

  8. Android权限安全(8)ContentProvider基于URI的安全

    一.provider可以通过binder得到客户的uid,然后进程权限检查. 二,provider临时权限 场景:  Email的内容在provider中提供,Email的客户端可读基其内容,现在一封 ...

  9. Androidz之Activity概要学习

    Androidz之Activity概要学习 1.     Activity类概述 Activity(活动)是一个单独的.能获取焦点的,且能与用户交互的东西.所以我们通常在Activity类中的onCr ...

  10. R programming, In ks.test(x, y) : p-value will be approximate in the presence of ties

    Warning message: In ks.test(x, y) : p-value will be approximate in the presence of ties   The warnin ...