2016 years Qingdao Network race---Tea

Source: Internet
Author: User

Topic links

http://acm.hdu.edu.cn/showproblem.php?pid=5881

problem DescriptionTea 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 leastL.

The exact volume of tea is at mostR.

Alice put the empty cups between and her.

Alice wants the both cups filled by almost equal volume of tea.

Yours cannot be1Unit more than hers.

Hers cannot be1 unit more than yours.

Alice wants you to pour the tea.

Alice wants 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 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. InputThere is multiple cases.
For each case, there are one line of integersLandR, separated by single space.

Here is some analyses about sample cases.
For the first case, pouring1Unit into one Cup would satisfy Alice.
For the second case, it's clearly that's cannot only pour once to reach the desired balance and she can achieve it by Pouring twice.
First you pour1.5Units into one cup and then you attempt to pour another1.5Units into the other Cup.
Since the lower bound is2, at least0.5Unit remains in the pot after the first pouring.
If the initial volume is in range[2,3] , the second Cup would have a volume in range[0.5,1.5] Which is balanced with1.5Unit in the first Cup, and at most1Unit remain after these-attempts.

About test Cases, and 0≤L ≤R≤ . OutputFor each case, there should is a single integer in a, the least number of pouring attempts. Sample Input2 22 4 Sample Output12 SourceACM/ICPC Asia Regional Qingdao Online

recommendwange2014 | We have carefully selected several similar problems for you:5891 5890 5889 5887 5886 Test Instructions: Enter L,R to indicate the volume range of tea in a pot of tea l~r, uncertain exact amount (whole Number), now to two cups of tea (regardless of cup capacity), the requirement to make two cups in a difference of less than 1, and tea in the tea pot can not exceed 1, the number of times to ask for the minimum; example explanation: 2 2 The answer is 1, we can pour 1 in the first Cup, the Second Cup does not fall, then two 1, the remaining amount of tea pot is 0~1, in line with the requirements of the topic; 2 4 The answer is 2, we can pour 1.5 into the first cup and then the Second Cup is 1.5, if the tea pot is 2, then the Second Cup is 0.5 twice times the difference 1 the teapot is 0 in accordance with the title, if the tea pot is 4 The same, the teapot remaining 1, in line with the requirements of the topic; thinking: First consider the general situation, the first cup pour (l+1)/2, the Second Cup according to (L+1)/2+1 pour, then if the teapot volume is l<= teapot <=l+2, the teapot is 0, two cups of tea difference 0~1; If the teapot is not empty, Then pour 2 into the first Cup, pour 2 in the Second Cup, pour 2 in the first cup ... Know the teapot is less than 2 (that is, the remaining amount of tea pot is 0 or 1), so that two cups of tea is always 1, in line with test instructions; code is as follows:
#include <iostream>#include<algorithm>#include<stdio.h>#include<queue>#include<cmath>#include<string.h>using namespacestd;intMain () {Long LongL,r;  while(SCANF ("%lld%lld", &l,&r)! =EOF) {        if(l==R) {if(r<=1) puts ("0"); Else if(r==2) puts ("1"); ElsePuts"2"); Continue; }        if(l==0)        {            if(r==1) puts ("0"); Else if(r==2) puts ("1"); Elseprintf"%lld\n", (r+1)/2); }        Else        {            if(l==1&&r==2) puts ("1"); Else{            if(L +2>=r-1) puts ("2"); Elseprintf"%lld\n", (r-l+2)/2); }        }    }    return 0;}

2016 years Qingdao Network race---Tea

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.