原题地址: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. iptables利用connlimit模块限制同一IP连接数

    connlimit功能: connlimit模块允许你限制每个客户端IP的并发连接数,即每个IP同时连接到一个服务器个数. connlimit模块主要可以限制内网用户的网络使用,对服务器而言则可以限制 ...

  2. Nginx include和Nginx指令的使用

    Nginx include和Nginx指令的使用 1.nginx include 主配置文件nginx.conf中指定包含其他扩展配置文件,从而简化nginx主配置文件,实现多个站点功能 [root@ ...

  3. [Unit Testing] Mock a Node module's dependencies using Proxyquire

    Sometimes when writing a unit test, you know that the module you're testing imports a module that yo ...

  4. Tomcat 编码不一致导致乱码

    众所周知,Tomcat是一个基于HTTP协议的Java应用服务器(非Web服务器),也是一个Servlet容器. 一般我们会基于使用HTTP协议的Post或Get方法来传递内容或参数,中间会涉及一些编 ...

  5. ContentProvider之通过ContentResolver获取图像、视频、音频举例

    MediaStore中定义了一系列的数据表格,通过ContentResolver提供的查询接口,我们能够得到各种须要的媒体信息.通过下面两个URI能够扫描设备外部和内部的媒体文件.Android系统提 ...

  6. Codeforces Round #254 (Div. 2) B (445B)DZY Loves Chemistry

    推理可得终于结果为2的(n-可分组合数)次方. 问题是怎么求出可分组合数,深搜就可以,当然并查集也能够. AC代码例如以下: 深搜代码!!! #include<iostream> #inc ...

  7. chown将指定文件的拥有者改为指定的用户或组(转)

    chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...

  8. rabbit 函数参数详解

    http://blog.csdn.net/chwshuang/article/details/50512057 http://www.cnblogs.com/LiangSW/p/6224333.htm ...

  9. Hive命令行经常使用操作(数据库操作,表操作)

    数据库操作 查看全部的数据库 hive> show databases ; 使用数据库default hive> use default; 查看数据库信息 hive > descri ...

  10. [linux]iostat命令详解-监视系统输入输出设备和CPU的使用情况

    部分转载https://blog.csdn.net/sunansheng/article/details/51942281 iostat命令被用于监视系统输入输出设备和CPU的使用情况.它的特点是汇报 ...