October 2016: Qingdao Network Competition --- Tea, 2016 Qingdao competition --- tea

Source: Internet
Author: User

October 2016: Qingdao Network Competition --- Tea, 2016 Qingdao competition --- tea

Question Link

Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 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 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 hours times.

You better pour as few times as possible. InputThere 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. OutputFor each case, there shocould be a single integer in a single line, the least number of pouring attempts. Sample Input2 22 4 Sample Output12 Source2016 ACM/ICPC Asia Regional Qingdao Online

 

RecommendWange2014 | We have carefully selected several similar problems for you: 5891 5890 5889 5887 5886 question: Input L, R indicates the volume range of tea in a pot L ~ R, not sure about the exact amount (integer). Now I need to pour tea into the two cups (regardless of the capacity of the cup), so that the difference between the two cups cannot exceed 1, the remaining tea in the teapot cannot exceed 1, and the minimum number of tea pouring is required. For example: 2 2. The answer is 1. We can pour 1 to the first cup, the second cup does not fall, so the difference between the two cups is 1, and the remaining amount of the teapot is 0 ~ 1. The answer is 2. You can enter 1.5 in the first cup. Then, press 1.5 in the second cup. If the tea volume in the teapot is 2, then the second cup is poured into 0.5 two times different 1 the teapot is 0 to meet the requirements of the subject, if the tea amount of the teapot is 4, the second cup is poured into 1.5 two cups the same amount, the remaining 1 of the teapot, meeting the requirements of the subject; train of Thought: first consider the general situation, the first cup into (L + 1)/2, the second cup according to (L + 1)/2 + 1, if the teapot quantity is L <= teapot <= L + 2, the teapot is 0, and the difference between the two teas is 0 ~ 1; if the teapot is not empty in bad circumstances, then add 2 to the first cup, 2 to the second cup, and 2 to the first cup ...... know that there are less than 2 teapot (that is, the remaining amount of the teapot is 0 or 1), so that the difference between the two cups of tea is always 1, consistent with the meaning of the question; the Code is as follows:
#include <iostream>#include <algorithm>#include <stdio.h>#include <queue>#include <cmath>#include <string.h>using namespace std;int main(){    long long L,R;    while(scanf("%lld%lld",&L,&R)!=EOF)    {        if(L==R)        {            if(R<=1) puts("0");            else if(R==2) puts("1");            else puts("2");            continue;        }        if(L==0)        {            if(R==1) puts("0");            else if(R==2) puts("1");            else printf("%lld\n",(R+1)/2);        }        else        {            if(L==1&&R==2)  puts("1");            else{            if(L+2>=R-1) puts("2");            else printf("%lld\n",(R-L+2)/2);            }        }    }    return 0;}

 

Related Article

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.