题目链接

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 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
 
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<=) puts("");
else if(R==) puts("");
else puts("");
continue;
}
if(L==)
{
if(R==) puts("");
else if(R==) puts("");
else printf("%lld\n",(R+)/);
}
else
{
if(L==&&R==) puts("");
else{
if(L+>=R-) puts("");
else printf("%lld\n",(R-L+)/);
}
}
}
return ;
}

2016 年青岛网络赛---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. 2016 年青岛网络赛---Family View(AC自动机)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...

  3. 2016 年青岛网络赛---Sort(k叉哈夫曼)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5884 Problem Description Recently, Bob has just learn ...

  4. HDU 5884 Sort(2016年青岛网络赛 G 二分+贪心+小优化)

    好题 题意:给你n<=100000个数,每个数范围[0,1000],然后给你一个最大的代价T,每次最多合并k个数成为一个数,代价为k个数的总和.问最后合成1个数的总代价不大于T的最小k 题解:我 ...

  5. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  6. 2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)

    2016 ACM/ICPC Asia Regional Qingdao Online(部分题解) 5878---I Count Two Three http://acm.hdu.edu.cn/show ...

  7. HDU 5886 Tower Defence(2016青岛网络赛 I题,树的直径 + DP)

    题目链接  2016 Qingdao Online Problem I 题意  在一棵给定的树上删掉一条边,求剩下两棵树的树的直径中较长那的那个长度的期望,答案乘上$n-1$后输出. 先把原来那棵树的 ...

  8. HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)

    I Count Two Three 31.1% 1000ms 32768K   I will show you the most popular board game in the Shanghai ...

  9. HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)

    Herbs Gathering 10.76% 1000ms 32768K   Collecting one's own plants for use as herbal medicines is pe ...

随机推荐

  1. WebApi系列~开放的CORS,跨域资源访问对所有人开放

    回到目录 之前有客户问我,如何AJAX跨域post,这个问题挺有意思,在我们看来,我是不被允许的,因为它是不安全的,但随着web api的火热,这个东西也被人们一步步的接受了,确实,有时,我们的接口希 ...

  2. Atitit 视频编码与动画原理attilax总结

    Atitit 视频编码与动画原理attilax总结 1.1. 第一步:实现有损图像压缩和解压1 1.2. 接着将其量化,所谓量化,就是信号采样的步长,1 1.3. 第二步:实现宏块误差计算2 1.4. ...

  3. Drupal网站开发实践--自定义购物流程

    由于Commerce模块自带的购物流程步骤过多,界面不太美观,所以需要重新设计. 改造后的购物流程分成两部:购物车->结算,就两个页面.购物车页面可以修改商品的数量,删除购物车内商品,查看总金额 ...

  4. Mysql 函数分类

    比较重要的 1 REVERSE(s)    将字符串s的顺序反过来 2 TRIM(s)          去掉字符串s开始和结尾处的空格 一.数学函数  数学函数主要用于处理数字,包括整型.浮点数等. ...

  5. 程序是如何执行的(一)a=a+1

    本文链接:http://www.orlion.ml/35/ 一.概述 1.计算机中有两个主要的核心部件:CPU和内存,其中CPU负责运算而内存负责存储程序和相关的变量,每一条程序语句和变量都在内存中有 ...

  6. jsp网站服务器配置

    Jsp网站部署环境配置 首先解释一下,.jsp网站与.html网站有着很大的不同,html是一种静态网站开发脚本语言,jsp则是在html的基础上专门为开发动态网站设计的语言.所以jsp网站没办法直接 ...

  7. 34988 Happy Reversal(二进制去取反)

    /* 题意:给多个二进制数,对某些数进行按位取反操作! 然后从中找到最大数和最小数,并输出他们的差值! 注意:所有的数都是整数,包括取反之后 思路:一个n为二进制数x,令tmp为n位全1!则 y=tm ...

  8. java多线程执行问题

    class Demo extends Thread{ public Demo(String name){ super(name); } public void run(){ for(int i=0; ...

  9. 在WPF应用程序中利用IEditableObject接口实现可撤销编辑的对象

    这是我辅导的一个项目开发中的例子,他们是用WPF做界面开发,在学习了如何使用MVVM来实现界面与逻辑的分离,并且很好的数据更新之后,有一个疑问就是,这种双向的数据更新确实很不错,但如果我们希望用户可以 ...

  10. 利用Dapper ORM搭建三层架构

    利用Dapper关系对象映射器写的简单的三层架构.Dapper:StackOverFlow在使用的一个微型的ORM,框架整体效率较高,轻量级的ORM框架.网上有较多的扩展.此处只是简单的调用Dappe ...