HDU 5881 Tea
Tea
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1008 Accepted Submission(s): 286
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.
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.
L 和 R 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1。你无法测量壶里剩下水的体积, 问最小需要倒水的次数。分析:- R<=1,茶壶里剩下不超过1,不用倒。倒0次。
- R<=2,从茶壶里向某一个杯子倒1,两个杯子里茶的差量最大为1,茶壶里剩下的最多为1。倒1次。
- L==R或者L+1==R,从茶壶里分别向两个杯子倒 L/2 。倒2次。
- L==0或者L==1情况等效(因为茶壶内可以留1升水)。
- 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的更多相关文章
- hdu 5881 Tea (2016 acm 青岛网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others) Me ...
- HDU 5881 Tea -2016 ICPC 青岛赛区网络赛
题目链接 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的 ...
- HDU 5881 Tea (模拟)
题意:有一壶水, 体积在 LLL 和 RRR 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水 ...
- Tea HDU - 5881
Tea is good. Tea is life. Tea is everything. The balance of tea is a journey of pursuing balance of ...
- 【2016 ACM/ICPC Asia Regional Qingdao Online】
[ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...
- hdu Hat's Tea
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1288 去买茶,需要正好的钱才行,另外花的钱的个数最多 其实是一个简单的贪心问题,小的多取一点,多的少 ...
- HDU 6667 Roundgod and Milk Tea (思维)
2019 杭电多校 8 1011 题目链接:HDU 6667 比赛链接:2019 Multi-University Training Contest 8 Problem Description Rou ...
- HDU 6667 Roundgod and Milk Tea
hdu题面 Time limit 6000 ms Memory limit 131072 kB OS Windows Source 2019 Multi-University Training Con ...
- hdu 1288 Hat's Tea
这个要慢慢理解…… ;}
随机推荐
- SPOJ 3643 /BNUOJ 21860 Traffic Network
题意:现在已有m条单向路,问在给你的k条双向路中选择一条,使得s到t的距离最短 思路:设双向路两端点为a,b;长度为c. s到t的有三种情况: 1:原本s到t的路径 2:从s到a,a到b,b再到t的路 ...
- SDUT2484算术表达式的转换
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2484&cid=1182 题目描述 小明在学习了数据结构之后,突然想起了以前没有解决的算术 ...
- hdu 2486/2580 / poj 3922 A simple stone game 博弈论
思路: 这就是K倍动态减法游戏,可以参考曹钦翔从“k倍动态减法游戏”出发探究一类组合游戏问题的论文. 首先k=1的时候,必败态是2^i,因为我们把数二进制分解后,拿掉最后一个1,那么会导致对方永远也取 ...
- hdu 1333 Smith Numbers
刚开始没看清题意,要找的数一定要是素数 ;}
- Android 虚拟机安装SD卡
在cmd命令行下,进入platform-tools目录下. 1.创建sdcard mksdcard -l mycard 256M E:\android\myCards\mysdcard.img ...
- js 后台异步执行
public void AlertMsg(string msg, bool async) { string script = string.Format("alert('{0}'); &qu ...
- Java实现二维码QRCode的编码和解码
涉及到的一些主要类库,方便大家下载: 编码lib:Qrcode_swetake.jar (官网介绍-- http://www.swetake.com/qr/index-e.html) 解码lib: ...
- P1011 传纸条//dp优化改进状态表示
P1011 传纸条 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2008复赛提高组第三题 描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不 ...
- 李洪强iOS学习交流群-iOS大神群
iOS学习大神群-群号:483959373
- leetcode:两个数的和||
两个数的和|| 给定一个排序数组,求出其中两个数的和等于指定target时,这两个数在原始数组中的下标,返回的下标从1开始 解题 原始数组已经是升序的,找出其中两个数的和等于target 定义两个指针 ...