Tea
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1114 Accepted Submission(s): 330
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
2016 ACM/ICPC Asia Regional Qingdao Online
当R<=1时 显然 一杯都不用倒 ans=0
当R=2时 倒一杯容量为1的
当R>2
倒的容量如下:
if L==0
1 2
2 2
2 2
.....
直到水壶水<=1
if L%2>0
L/2+1 L/2+2
2 2
2 2
直到水壶中水<=1
if L%2==0
L/2+0.5 L/2+1.5
2 2
2 2
2 .....
直到水壶中剩余的水<=1
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<math.h>
#include<list>
#include<cstring>
#include<fstream>
//#include<memory.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define INF 1000000007
#define pll pair<ll,ll>
#define pid pair<int,double>
int main()
{
//freopen("/home/lu/文档/r.txt","r",stdin);
//freopen("/home/lu/文档/w.txt","w",stdout);
ll l,r;
while(~scanf("%lld%lld",&l,&r)){
ll ans=0;
if(r<=2){
printf("%lld\n",r==0?0:r-1);
continue;
}
ll reside=r;
if(reside%2>0||l==0){
reside-=l/2+1;
reside-=l/2+2;
}
else{
reside*=10;
reside-=l*5+5;
reside-=l*5+15;
reside/=10;
}
ans=2;
if(reside>1)
ans+=reside/2;
printf("%lld\n",ans);
}
return 0;
}

本题是一道关于在有限条件下如何平均分配茶水的算法题目。玩家需根据茶壶内茶水体积范围,通过最少次数的倒茶操作使两个杯子中的茶水体积尽可能接近且茶壶内剩余不超过1单位体积的茶水。
2493

被折叠的 条评论
为什么被折叠?



