[CareerCup] 6.3 Water Jug 水罐问题
6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible.
这道题给了我们两个水罐,一个是5夸脱的,一个是3夸脱的,还有无限的水,让我们测量出4夸脱的水,前提是我们不能每次给容器装一半的水,那么这需要来回倒好几次,才能装出4夸脱的水,参见步骤如下:
|
5夸脱水罐当前水量 |
3夸脱水罐当前水量 |
步骤 |
|
5 |
0 |
装满5夸脱水罐 |
|
2 |
3 |
用5夸脱水罐装满3夸脱水罐 |
|
2 |
0 |
倒空3夸脱水罐 |
|
0 |
2 |
把5夸脱水罐中的水倒入3夸脱水罐 |
|
5 |
2 |
装满5夸脱水罐 |
|
4 |
3 |
用5夸脱水罐装满3夸脱水罐 |
|
4 |
我们得到了4夸脱的水 |
[CareerCup] 6.3 Water Jug 水罐问题的更多相关文章
- CareerCup All in One 题目汇总 (未完待续...)
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...
- CareerCup All in One 题目汇总
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...
- 深度学习之加载VGG19模型分类识别
主要参考博客: https://blog.csdn.net/u011046017/article/details/80672597#%E8%AE%AD%E7%BB%83%E4%BB%A3%E7%A0% ...
- ImageNet2017文件下载
ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...
- ImageNet2017文件介绍及使用
ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- 【LeetCode】365. Water and Jug Problem 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学题 相似题目 参考资料 日期 题目地址:http ...
- Leetcode: Water and Jug Problem && Summary: GCD求法(辗转相除法 or Euclidean algorithm)
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- 【leetcode】365. Water and Jug Problem
题目描述: You are given two jugs with capacities x and y litres. There is an infinite amount of water su ...
随机推荐
- iOS开发网络篇—网络编程基础(二)
下面叙述的是关于几个必须要知道的iOS网络编程入门级别的要点: 1.客户端如何找到连接的服务器 客户端通过URL找到想要连接的服务器 2.什么是URL URL的全称是Un ...
- 返回顶部 和ico标题图片的制作
<link rel="shortcut icon" href="bitbug_favicon.ico">---比特虫ico网页快速制作<tit ...
- 常用vi编辑命令
在自己的博客里存起来,这么多全记住确实有点难,时不时的翻一翻到是可以的. 摘自:http://www.cnblogs.com/junw_china/articles/1708967.html 光标控制 ...
- cocos2d-x之首选项数据初试
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...
- javascript 内部对象(1)——Math 对象
Math是javascript中的内部对象之一,主要用于处理数学方面的任务,是一种静态对象.和其他动态对象如Date.String等不同的是它没有构造函数Math(),可以直接使用属性和方法. 例如使 ...
- KD Tree算法
参考:http://blog.csdn.net/v_july_v/article/details/8203674 #!/user/bin/env python # -*- coding:utf8 -* ...
- DirectX API 编程起步 #02 窗口的诞生
在这篇文章里我们先用 windows API 制作一个窗口出来,以后再用 DirectX API 渲染的东西就会显示在这里,控制台那黑白的画面肯定是没法用的. 每次的代码都会更新到Github 首先贴 ...
- OpenGL 学习笔记 01 环境配置
以下教程仅适用于Mac下的Xcode编程环境!其他的我也不会搞. 推荐教程:opengl-tutorial 本项目Github网址 OpenGL太可怕了...必需得把学的记下来,不然绝壁 ...
- EXCEL IF 函数 模糊查询
A列都是产品名,比如衬衫,长袖衬衫,短袖衬衫,短裙,长裙 搜索A列的产品名,凡是含有“衬衫”的一律在B列对应行输出“衬衫”,凡是含有“裙”字的一律输出“裙子”在B列对应行,请教一下怎么写函数,本来用I ...
- 小结getBytes()默认编码导致的xml字符串中出现乱码
遇到乱码第一印象想到的是如何统一编码,很少注意到这期间穿插的某些过程也是一大隐患.. sae上部署了一个spring写的微信小程序,手机总关注测试号点击菜单得到的文本消息却是乱码.. 聚焦发送消息的部 ...