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

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≤LR≤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

题意:

从茶壶里向两个杯子里倒茶,茶壶里茶的体积 在[L,R]区间,我们只知道有没有倒完,但不知道还剩多少。

最后两个杯子里茶的差量不能超过1,茶壶里不能剩下超过1。问最少倒几次。

解:

R<=1 茶壶里剩下不超过1,不用倒,0次。

R<=2  从茶壶里向某一个杯子倒 1,两个杯子里茶的差量最大为1,茶壶里剩下的最多为1。倒1次。

L==R或者L==R-1 ,从茶壶里分别向两个杯子倒 L/2 , 倒2次。

L==0或者L==1情况相同。

R>L+1时,先向一个杯子倒L/2,再向另一个倒L/2+1, 再轮流重复向两个杯子里倒2,直到倒完(最多剩下1).

#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 long

using 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;
}
时间: 2024-12-22 10:51:03

hdu 5881 Tea (2016 acm 青岛网络赛)的相关文章

HDU 5881 Tea -2016 ICPC 青岛赛区网络赛

题目链接 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的体积, 问最小需要倒水的次数. 题解:考虑倒水的大致过程,L = 0 和 L = 1 的情况应该是等价的,所以不妨设 L > 0.首先向一个杯子倒 L/2 升水,再往另一个杯子倒  L/2+1 升水.接下来就来回往两个杯子里倒 2 升,直到倒空为止.这样就很容易分析出需要倒水的次数.唯一注意的是最后

2016 年青岛网络赛---Tea

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5881 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 te

2016 年青岛网络赛---Sort(k叉哈夫曼)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5884 Problem Description Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from Alice.Alice will give Bob N sorted sequences, and the i-th sequence includes ai

2016 年青岛网络赛---Family View(AC自动机)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribution platform developed by Valve Corporation offering digital rights management (DRM), multiplayer gaming and social networking services. A family view

2016 acm香港网络赛 B题. Boxes

原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N.Each box may (or not may not) be put into other boxes. These boxes together form a tree structure (or a forest structure, to be precise). You have to

2016 acm香港网络赛 C题. Classrooms(贪心)

原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and finding classrooms for orientation activities is always a headache. There are k classrooms on campus and n proposed activities that need to be assigne

2016 acm香港网络赛 A题. A+B Problem (FFT)

原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/archive/2013/07/24/3210565.html A+B Problem Given N integers in the range [−50000,50000], how many ways are there to pick three integers ai, aj, ak, such

HDU 5875 Function (2016年大连网络赛 H 线段树+gcd)

很简单的一个题的,结果后台数据有误,自己又太傻卡了3个小时... 题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对数字b取模时:如果a<b,则等于原数,否则a会变小至少一半.就是说a最多成功取模(log2 a)次,所以我们只需要每次在区间内找到最前面一个小于等于a的值,接着更新a与区间左端点,直到没有值比a小或者区间取模完成. 我们可以使用线段树求出区间内小于某个值的最前一个位置,具体方法就是:父节点记录区间最

2016 acm香港网络赛 F题. Crazy Driver(水题)

原题网址:https://open.kattis.com/problems/driver Crazy Driver In the Linear City, there are N gates arranged in a straight line. The gates are labelled from 1 to N. Between adjacent gates, there is a bidirectional road. Each road takes one hour to travel