【HDU - 5881】Tea(思维,找规律)

题干:

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 LL. 

The exact volume of tea is at most RR. 

Alice put two empty cups between you and her. 

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

Yours cannot be 11 unit more than hers. 

Hers cannot be 11 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 11 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 LL and RR, separated by single space. 

Here are some analyses about sample cases. 
For the first case, pouring 11 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.51.5 units into one cup, then you attempt to pour another 1.51.5 units into the other cup. 
Since the lower bound is 22, at least 0.50.5 unit remains in the pot after the first pouring. 
If the initial volume is in range [2,3][2,3], the second cup will have volume in range [0.5,1.5][0.5,1.5] which is balanced with 1.51.5 unit in the first cup, and at most 11 unit remain after these two attempts. 

About 10001000 test cases, and 0≤L≤R≤10160≤L≤R≤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

题目大意:

有一壶水, 体积在 L 和 R 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的体积, 问最小需要倒水的次数。

解题报告:

就是个找规律题,没啥意思,为了保险就特判了一堆。

第一次倒给第一个杯子L/2+0.5是比较合适的,第二次倒给第二个杯子L/2+0.5+1,再给第一个杯子倒2L,继续这样直到壶只剩小于等于1L。

最后的公式就是 (R - L) / 2  + 1。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;int main()
{ll l,r;while(~scanf("%lld%lld",&l,&r)) {if(r <= 1) puts("0");else if(r <= 2) puts("1");else if(l == 0) {printf("%lld\n",(r-1)/2 + 1);}else if(l == r || l+1 == r|| l+2==r) puts("2");else {printf("%lld\n",1+(r-l)/2);}}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440232.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Apollo自动驾驶入门课程第⑦讲 — 规划(上)

目录 1. 规划简介 2. 将地图转为图形 3. 路径查找算法&#xff1a;A* 4. 轨迹生成 5. Fernet坐标系 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿波君 Apollo开发者社区 9月13日 上周我们发布了无人驾驶技术的 预测篇&#xff0c;简要介绍了预测的…

JS正则表达式常见场景下的用法总结

&#xff08;一&#xff09;前置知识总结&#xff1a; 1. 正则表达式 /xxxx/[标识] 其中的标识含义 •g &#xff08;全文查找&#xff09; •i &#xff08;忽略大小写&#xff09; •m &#xff08;多行查找&#xff09; 2. 正则表达式创建的两种方式&#xff08;等价&#…

【HDU - 5882】Balanced Game (找规律,思维)

题干&#xff1a; Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper", and "scisso…

Apollo自动驾驶入门课程第⑧讲 — 规划(下)

目录 1. 路径-速度解耦规划 2. 路径生成与选择 3. ST图 4. 速度规划 5. 优化 6. 路径-速度规划的轨迹生成 7. Lattice规划 8. ST轨迹的终止状态 9. SL轨迹的终止状态 10. Lattice规划的轨迹生成 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿…

网络编程懒人入门(五):快速理解为什么说UDP有时比TCP更有优势

转自即时通讯网&#xff1a;http://www.52im.net/ 本文观点仅作参考&#xff0c;请根据自已系统的应用场景合理地选择数据传输层协议即可&#xff0c;无需盲目崇拜大牛言论。 1、前言 对于即时通讯开者新手来说&#xff0c;在开始着手编写IM或消息推送系统的代码前&#xff…

CSS定位总结:position=static/relative/absolute/fixed时的区别、top/bottom/left/right与margin外边距的运用

准备布局&#xff1a; <!DOCTYPE html> <html> <head> <style> *{ margin:0; padding:0; } .base-container{width: 500px;height: 500px;background-color:lightgray;border:1px dashed red; } .base-compare {width:200px;height:100px;background…

【HDU - 5883】The Best Path(判断欧拉回路)

题干&#xff1a; Alice is planning her travel route in a beautiful valley. In this valley, there are NN lakes, and MM rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up …

网络编程懒人入门(六):史上最通俗的集线器、交换机、路由器功能原理入门

转自即时通讯网&#xff1a;http://www.52im.net/ 本文引用了知乎网友“薛定谔不在家”的部分文字内容&#xff0c;感谢原作者的分享。 1、前言 即时通讯网整理了大量的网络编程类基础文章和资料&#xff0c;包括《TCP/IP协议 卷1》、《[通俗易懂]深入理解TCP协议》系列、《…

总结JSON.parse()报错VM71:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0等之类的问题

问题场景&#xff1a;在调试前端应用的时候经常出现形如“Uncaught SyntaxError: Unexpected”之类的令人头疼觉得莫名其妙的问题&#xff1b;所以有必要总结整理一下关于JSON.parse()这个API方法的注意事项。以便在以后的开发中出现类似的问题能第一时间想到可能是这个方法的参…

【HDU - 5884】Sort(k叉哈夫曼树,优化tricks,两个队列代替优先队列)

题干&#xff1a; Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from Alice. Alice will give Bob NN sorted sequences, and the ii-th sequence includes aiai elements. Bob need to merge all of these sequences. H…

金额输入框校验和自动校正、支持指定任意位数小数decimal、支持只能输入整数、支持是否允许输入负数等功能

应用场景&#xff1a;开发前端交互页面时&#xff0c;经常遇到金额输入框、指定小数位数的数字输入框&#xff0c;单一的正则表达式无法满足大部分的业务校验需求&#xff0c;下面总结一个实用巧妙而又灵活的把普通输入框变成自动校正输入框的解决方案&#xff1a; 数字&#…

网络编程懒人入门(七):深入浅出,全面理解HTTP协议

转自即时通讯网&#xff1a;http://www.52im.net/ 本文引用了自简书作者“涤生_Woo”的文章&#xff0c;内容有删减&#xff0c;感谢原作者的分享。 1、前言 HTTP&#xff08;全称超文本传输协议&#xff0c;英文全称HyperText Transfer Protocol&#xff09;是互联网上应用…

【HDU - 5889】Barricade(最短路+网络流,最小割)

题干&#xff1a; The empire is under attack again. The general of empire is planning to defend his castle. The land can be seen as NN towns and MM roads, and each road has the same length and connects two towns. The town numbered 11 is where generals cast…

SM4国密对称算法源码解析

最近在研究国密算法&#xff0c;主要分为&#xff1a;SM2、SM3、SM4。其中SM2为非对称加密算法&#xff0c;SM3为哈希摘要算法&#xff0c;SM4为对称加密算法。 1.在SM4算法源文件中主要有以下几个函数&#xff1a; void sm4_setkey_enc( sm4_context *ctx, unsigned char ke…

Mac系统容易忽视但很实用的命令整理

001.终端指定用哪个软件打开指定的文件 # open -a 实用哪个软件(软件名有空格需转义) 文件名路径 open -a /Applications/Google\ Chrome.app xx.html # 【tips:】由于先输入"open -a"后tab键自动补全容易卡死终端&#xff0c;所以推荐先输入"/App..."&a…

【HDU 4394】Digital Square(bfs,数位搜索,思维,数学)

题干&#xff1a; Given an integer N,you should come up with the minimum nonnegative integer M.M meets the follow condition: M 2%10 xN (x0,1,2,3....) Input The first line has an integer T( T< 1000), the number of test cases. For each case, each line…

SM4算法原理

前面的文章介绍了SM4算法的C语言实现&#xff0c;源码可见文章&#xff1a;SM4国密对称算法源码解析_10点43的博客-CSDN博客_sm4代码。 本文将会介绍SM4算法原理&#xff0c;这部分可能会比较枯燥&#xff0c;但数学要求也不是太高。 目录 1.概述 2. 参数产生 3. 轮函数 4…

webpack打包前端项目入门

前言&#xff1a;在开发过程中&#xff0c;利用webpack可以帮我们自动把ES6语法编译成低版本浏览器能解析的JavaScript代码。下面给出webpack打包前端项目入门案例。 [终端&#xff1a;进入项目所在目录] 1.初始化项目依赖&#xff1a; npm init -y 2.安装webpack-cli脚手架…

网络编程懒人入门(八):手把手教你写基于TCP的Socket长连接

转自即时通讯网&#xff1a;http://www.52im.net/ 本文原作者&#xff1a;“水晶虾饺”&#xff0c;原文由“玉刚说”写作平台提供写作赞助&#xff0c;原文版权归“玉刚说”微信公众号所有&#xff0c;即时通讯网收录时有改动。 1、引言 好多小白初次接触即时通讯&#xff…

【HihoCoder - 1502】最大子矩阵(二维前缀和,尺取)

题干&#xff1a; 给定一个NxM的矩阵A和一个整数K&#xff0c;小Hi希望你能求出其中最大&#xff08;元素数目最多&#xff09;的子矩阵&#xff0c;并且该子矩阵中所有元素的和不超过K。 Input 第一行包含三个整数N、M和K。 以下N行每行包含M个整数&#xff0c;表示A。 对…