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. Chp11: Sorting and Searching

    Common Sorting Algo: Bubble Sort: Runime: O(n2) average and worst case. Memory: O(1). void BubbleSor ...

  2. hdu 1005 Number Sequence(矩阵快速幂,找规律,模版更通用)

    题目 第一次做是看了大牛的找规律结果,如下: //显然我看了答案,循环节点是48,但是为什么是48,据说是高手打表出来的 #include<stdio.h> int main() { ], ...

  3. Class

    1. No const constructor Unlike other member functions, constructors may not be declared as const . W ...

  4. JavaScript执行上下文

    变量声明.函数声明为何会提升?js执行时是如何查找变量的?JavaScript中最基本的部分——执行上下文(execution context) 什么是执行上下文? 当JavaScript代码运行,执 ...

  5. POJ1276Cash Machine

    http://poj.org/problem?id=1276 题意 : 给你一个目标钱数,再给你钱币的种数和钱币的面值,让你用这些钱凑出不大于目标钱数的钱然后输出这个最接近且不大于目标钱数的钱. 思路 ...

  6. POJ 3278Catch That Cow

    http://poj.org/problem?id=3278 大意是说牛在原地不动,他在某点去抓牛,他有两种方式可以走,第一种走一步,往前往后都可,第二种是走现在所在点的两倍的数目.只要能够刚好到达牛 ...

  7. 欧拉工程第72题:Counting fractions

    题目链接:https://projecteuler.net/problem=72 真分数;n/d 当d ≤ 1,000,000时候的真分数有多少个 public class P72{ void run ...

  8. 只有innoDB才允许使用外键

    1.只有InnoDB引擎才允许使用外键,所以,我们的数据表必须使用InnoDB引擎. 2.注意: 1.必须使用InnoDB引擎: 2.外键必须建立索引(INDEX): 3.外键绑定关系这里使用了“ O ...

  9. TCL语言笔记:TCL中的控制结构命令

    一.引言 控制结构允许程序根据不同的状态.条件和参数来选择不同的处理和执行路径,从而使代码具有更强的灵活性.健壮性和可读性. Tcl 提供了 if.if/else.if/elseif.foreach. ...

  10. 被称为同步神器的 BTSync,你可以怎么用?

    在这高速运作的信息化时代,使用云端来衔接工作和生活的点滴已是寻常事.可你是否曾扪心自问过:用各大云端备份自己的信息资料,真的安全放心吗? 毫不夸张的说,其实恶意代码和漏洞早已和你如影随形.你甚至都不用 ...