[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之UI--自定义IOS的HYCheckBox源码的使用
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- genymotion虚拟机启动失败
错误提示如下: Make sure that you have installed it correctly before starting Genymotion. 解决方法(重启VirtualBox ...
- [转]Designing a User Interface
UI design can be divided into three essential elements : functionality, aesthetics, and performance. ...
- solr 导入数据
从sqlserver导入数据到solr, solr 采用的版本6.0.1,并且本机解压到:F:\Tool\solr-6.0.1: 1. 命令启动solr,创建core 启动,进入solr文件目录下,执 ...
- mysql数据库---同时插入两个表以上的数据
mysql数据库问题,如何同一个操作添加两个表(a表,b表),并把b表的id添加到a表字段中,b表id自动增长 在数据库中创建存储过程,比如存储过程的名字叫做 test在java中和正常使用sql的方 ...
- 面试之jsp、Servlet相关知识——生命周期, 区别等
1.servlet生命周期 所谓生命周期,指的是servlet容器如何创建servlet实例.分配其资源.调用其方法.并销毁其实例的整个过程. 阶段一: 实例化(就是创建servlet对象,调用构造器 ...
- FileOutputFormat
TextOutputFormat<K,V> 默认输出字符串输出格式: SequenceFileOutputFormat<K,V> 序列化文件输出: MultipleOutput ...
- 【MVC 4】7.SportsSore:完成购物车
作者:[美]Adam Freeman 来源:<精通ASP.NET MVC 4> 本文将继续构建 SportsStore 示例应用程序.在上一章中,添加了对购物车的基本支持,现在打 ...
- 有限状态机HDL模板
逻辑设计, 顾名思义, 只要理清了逻辑和时序, 剩下的设计只是做填空题而已. 下面给出了有限状态机的标准设计,分别为 VHDL 和 Verilog 代码 1 有限状态机 2 VHDL模板之一 li ...
- 用Python和摄像头制作简单的延时摄影
“延时摄影(英语:Time-lapse photography)是以一种较低的帧率拍 下图像或者视频,然后用正常或者较快的速率播放画面的摄影技术.在一段延时摄影视频中,物体或者景物缓慢变化的过程被压缩 ...