原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881

Tea

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 451    Accepted Submission(s): 124

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≤LR≤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

2016 ACM/ICPC Asia Regional Qingdao Online

 
题意:
从茶壶里向两个杯子里倒茶,茶壶里茶的体积 在[L,R]区间,我们只知道有没有倒完,但不知道还剩多少。
最后两个杯子里茶的差量不能超过1,茶壶里不能剩下超过1。问最少倒几次。
 
解:
R<=1 茶壶里剩下不超过1,不用倒,0次。
R<=2  从茶壶里向某一个杯子倒 1,两个杯子里茶的差量最大为1,茶壶里剩下的最多为1。倒1次。
L==R或者L==R-1 ,从茶壶里分别向两个杯子倒 L/2 , 倒2次。
L==0或者L==1情况相同。
R>L+1时,先向一个杯子倒L/2,再向另一个倒L/2+1, 再轮流重复向两个杯子里倒2,直到倒完(最多剩下1).
#include<stdio.h>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cstdio>
#include <cmath> #define LL long long using namespace std;
LL l,r; LL solve(LL l,LL r)
{
if(r<=) return ;
if(r<=) return ;
if(l==r||l==r-) return ;
if(l<=) l=;
return (r-l)/+;
} int main()
{
while(scanf("%lld%lld",&l,&r)!=EOF)
{
cout<<solve(l, r)<<endl;
}
return ;
}
 
 
 
 

hdu 5881 Tea (2016 acm 青岛网络赛)的更多相关文章

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

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

  2. 2016 年青岛网络赛---Tea

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5881 Problem Description Tea is good. Tea is life. Te ...

  3. 2016 年青岛网络赛---Family View(AC自动机)

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

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

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

  5. HDU 5901 Count primes (2016 acm 沈阳网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...

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

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

  7. HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...

  8. 2016 acm香港网络赛 C题. Classrooms(贪心)

    原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...

  9. 2016 acm香港网络赛 B题. Boxes

    原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N ...

随机推荐

  1. TQ2440平台上LCD驱动的移植

    参考: http://liu1227787871.blog.163.com/blog/static/205363197201242393031250/ http://blog.csdn.net/cum ...

  2. python pep8编码风格学习记录(转)

    简要归纳 每个缩进层级使用4个空格. 每行最多79个字符. 顶层的函数或类的定义之间空两行. 采用ASCII或UTF-8编码文件 在文件顶端,注释和文档说明之下,每行每条import语句只导入一个模块 ...

  3. http://blog.csdn.net/emoven/article/details/12999265

    http://blog.csdn.net/emoven/article/details/12999265

  4. log4j教程 7、日志记录级别

    org.apache.log4j.Level类提供以下级别,但也可以通过Level类的子类自定义级别. Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调 ...

  5. elasticsearch 安装和部署

    jdk要用1.8以上(elasticsearch版本是1.7.3) 下载elasticsearch的tar包,解压开,更改其名称  mv elasticsearch-5.x.x elasticsear ...

  6. Word文档打不开怎么办

    目前一些主流的办公软件给大家日常工作带来了很大便利,比如:Microsoft Office或金山WPS!我们在愉快地使用它们的同时,多少也遇到了一些让人尴尬或头疼的问题,比如:精心制作的文档,突然打不 ...

  7. 模拟服务器MockServer之Moco详细介绍

    转载:http://blog.csdn.net/vite_s/article/details/54583243 前面一篇介绍了如何用mockito来测试我们的一些异步任务,例如网络请求时候的异步回调. ...

  8. PS PNG导出的时候是否交错有什么影响

    已解决 导出png格式交错什么意思 我百度的答案一律说png支持交错,可是交错两个字的意思是什么啊,那位专家请指教.谢谢啦!! 问题补充: 我用photoshop或者coreldraw制作按钮时候不是 ...

  9. snmp弱口令引起的信息泄漏

    0x00 snmp协议简介 snmp协议即简单网络管理协议(SNMP,Simple Network Management Protocol).目前一共有3个版本:V1,V2c,V3.V3是最新的版本, ...

  10. python特殊函数

    __doc__  类(实例).__doc__ 类的描述信息 '''class des''' __module__ 类(实例).__module__ 表示当前操作的对象在那个模块 __class__   ...