首页 > 代码库 > hdu 5881 Tea (2016 acm 青岛网络赛)
hdu 5881 Tea (2016 acm 青岛网络赛)
原题地址: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
ProblemDescription
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 1unit more than hers.
Hers cannot be 1unit 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 1unit 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 Land R,separated by single space.
Here are some analyses about sample cases.
For the first case, pouring 1 unit into one cup willsatisfy Alice.
For the second case, it is clearly that you cannot only pour once to reach thedesired balance, but she can achieve it by pouring twice.
First you pour 1.5units into one cup, then you attempt to pour another 1.5units into the other cup.
Since the lower bound is 2,at least 0.5unit 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.5unit in the first cup, and at most 1unit remain after these two attempts.
About 1000test cases, and 0≤L≤R≤1016.
Output
For each case, there should be a singleinteger in a single line, the least number of pouring attempts.
SampleInput
2 2
2 4
Sample Output
1
2
Source
2016 ACM/ICPC Asia Regional Qingdao Online
#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 longusing namespace std;LL l,r;LL solve(LL l,LL r){ if(r<=1) return 0; if(r<=2) return 1; if(l==r||l==r-1) return 2; if(l<=1) l=1; return (r-l)/2+1;}int main(){ while(scanf("%lld%lld",&l,&r)!=EOF) { cout<<solve(l, r)<<endl; } return 0;}
hdu 5881 Tea (2016 acm 青岛网络赛)