Tea
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 354 Accepted Submission(s): 84
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.
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 .
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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5881
一个智商题,智商还不够啊。
题解:
题意:有一壶水, 体积在 L
和 R
之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1),并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的体积, 问最小需要倒水的次数。
题解:考虑倒水的大致过程,L=0
和 L=1
的情况应该是等价的,所以不妨设 L>0
。首先向一个杯子倒 2L
升水,再往另一个杯子倒 2L+1
升水。接下来就来回往两个杯子里倒 2 升,直到倒空为止。这样就很容易分析出需要倒水的次数。唯一注意的是最后壶里面可以剩下 1 升水,可以省一次倒水的操作。
题解链接:https://async.icpc-camp.org/d/558-2016
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(){
long long L,R;
while(~scanf("%lld%lld",&L,&R)){
long long top=0;
if(R<=1){//特判一下
cout<<"0"<<endl;
continue;
}
else if(R<=2){
cout<<"1"<<endl;
continue;
}
if(L==0){
L=1;
}
if(R-L<=3){
cout<<"2"<<endl;
}
else{
cout<<2+(R-L-2)/2<<endl;
}
}
return 0;
}