HDU 5881 Tea (ACM Qingdao online game)

Source: Internet
Author: User

Original title address: 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 the empty cups between and her.
Alice wants the both cups filled by almost equal volume of tea.
Yours cannot is 1unit more than hers.
Hers cannot is 1unit more than yours.
Alice wants you to pour the tea.
Alice wants 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 be know the tea status in the pot, empty or not.
Alice does not want your to pour the tea too many times.
You better pour as few times as possible.

Input

There is multiple cases.
For each case, there are one line of integers Land R, separated by single space.

Here is some analyses about sample cases.
For the first case, pouring 1 unit into one Cup willsatisfy Alice.
For the second case, it's clearly that's cannot only pour once to reach thedesired balance and she can achieve it by P Ouring twice.
First you pour 1.5units into one cup and 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'll has volume in range [0.5,1.5]which are balanced with 1.5unit I n the first cup, and at most 1unit remain after these-attempts.

About 1000test cases, and 0≤LR≤1016.

Output

For each case, there should is a singleinteger in a, the least number of pouring attempts.

Sampleinput

2 2
2 4

Sample Output

1
2

Source

ACM/ICPC Asia Regional Qingdao Online

Test instructions: Pour the tea from the teapot into two cups, and in the teapot the volume in the [L,r] range, we only know if we have finished, but do not know how much left. The last two cups of tea can not be more than 1 of the difference, the teapot can not be left more than 1. Ask at least a few times. Solution: R<=1 teapot is not more than 1, do not pour, 0 times. R<=2 from the teapot to a cup 1, two cups of tea in the difference between the maximum of 1, the remaining tea pot is up to 1. Pour 1 times. L==r or l==r-1, pour the two cups from the teapot to 2 and pour 2 times. L==0 or l==1 are the same situation. When r>l+1, pour the L/2 to a cup, then pour the l/2+1 to the other, and then repeat to two cups in turn 2 until the end (up to 1 left).
#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>#defineLL Long Longusing namespacestd; 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;}intMain () { while(SCANF ("%lld%lld", &l,&r)! =EOF) {cout<<solve (l, R) <<Endl; }    return 0;}

HDU 5881 Tea (ACM Qingdao online game)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.