博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2016 年青岛网络赛---Tea
阅读量:5348 次
发布时间:2019-06-15

本文共 3020 字,大约阅读时间需要 10 分钟。

题目链接

 

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 0LR1016.
 
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
 

 

Recommend
wange2014   |   We have carefully selected several similar problems for you:            
 
题意:输入L,R 表示一壶茶的茶的体积的范围L~R,不确定精确量(整数), 现在往两个茶杯中倒茶(不考虑茶杯容量) ,要求使两个茶杯中茶相差不超过1 ,而茶壶中剩余的茶不能超过1, 求最少倒茶的次数;
        样例解释一下:2 2 答案是1 ,我们可以往第一个茶杯中倒1 ,第二杯不倒, 那么两个茶杯相差为1 ,茶壶剩余量为0~1 , 符合题目要求; 2 4 答案是2 ,我们可以往第一杯倒入1.5  那么第二杯按1.5 到,如果茶壶 茶量为2,那么第二杯倒入0.5 两倍相差1 茶壶为0 符合题目要求,如果茶壶 茶量为4, 第二杯倒入1.5 两杯量相同, 茶壶剩余1, 符合题目要求;
 
思路: 先考虑普通情况,第一杯倒入(L+1)/2, 第二杯按照(L+1)/2+1倒, 那么如果茶壶量为L<=茶壶<=L+2 ,则茶壶为0 了,两杯茶相差0~1 ;如果情况糟糕茶壶不空,那么接下来往第一杯中倒入2 ,第二杯中倒入2 ,第一杯中倒入2 ......知道茶壶不足2 (即茶壶剩余量为0或者1) ,这样两杯茶始终相差1,符合题意;
 
代码如下:
#include 
#include
#include
#include
#include
#include
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;}

 

转载于:https://www.cnblogs.com/chen9510/p/5879710.html

你可能感兴趣的文章
在Silverlight中使用HierarchicalDataTemplate为TreeView实现递归树状结构
查看>>
无线通信基础(一):无线网络演进
查看>>
如何在工作中快速成长?阿里资深架构师给工程师的10个简单技巧
查看>>
WebSocket 时时双向数据,前后端(聊天室)
查看>>
关于python中带下划线的变量和函数 的意义
查看>>
linux清空日志文件内容 (转)
查看>>
安卓第十三天笔记-服务(Service)
查看>>
Servlet接收JSP参数乱码问题解决办法
查看>>
Ajax : load()
查看>>
MySQL-EXPLAIN执行计划Extra解释
查看>>
Zookeeper概述
查看>>
Zookeeper一致性级别
查看>>
Linux远程登录
查看>>
Linux自己安装redis扩展
查看>>
HDU 1016 Prime Ring Problem(dfs)
查看>>
C#中结构体与字节流互相转换
查看>>
session和xsrf
查看>>
Linux目录结构
查看>>
luoguP3414 SAC#1 - 组合数
查看>>
五一 DAY 4
查看>>