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 水罐问题的更多相关文章

  1. CareerCup All in One 题目汇总 (未完待续...)

    Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...

  2. CareerCup All in One 题目汇总

    Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...

  3. 深度学习之加载VGG19模型分类识别

    主要参考博客: https://blog.csdn.net/u011046017/article/details/80672597#%E8%AE%AD%E7%BB%83%E4%BB%A3%E7%A0% ...

  4. ImageNet2017文件下载

    ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...

  5. ImageNet2017文件介绍及使用

    ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...

  6. [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 ...

  7. 【LeetCode】365. Water and Jug Problem 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学题 相似题目 参考资料 日期 题目地址:http ...

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

  9. 【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 ...

随机推荐

  1. android 进程间通信---Service Manager(2)

    关于servicemanager的设计: 还是这张结构图,由于ProcessState & IPCThreadState是与binder deriver交互的, 所以对于client端来说Bp ...

  2. android 进程间通信数据(二)------parcel的实现

    Serialize是java原生就自带的东西,我们可以看到android的源码 所以看看android是如何实现parcel的,这对我们自己代码设计有什么启发. Parcel: 在android中,p ...

  3. XtraScheduler 日程控件显示自定义标题

    下面代码实现一个自定义日程标题 public class CustomHeaderCaptionService : HeaderCaptionServiceWrapper { public Custo ...

  4. 深入PHP内核之ZVAL

    一.PHP的变量类型 PHP的变量类型有8种: 标准类型:布尔boolen,整型integer,浮点float,字符string 复杂类型:数组array,对象object 特殊类型:资源resour ...

  5. Android 开发之 Android 开发的起步

    前言  Android 开发的起步 我们可以先来看看百科上面怎么说? 百度百科上 Android的介绍 一.Windows环境下在线搭建Android环境. 1. 下载 Android开发工具. JD ...

  6. 虚拟机centos6.5 --VirtualBox设置全屏

    一.安装以下模块 yum install kernel-devel kernel-headers gcc,然后重启. 二.安装增强功能 安装失败,查看日志文件,cat /var/log/vboxadd ...

  7. TCP/IP详解--TCP首部选项中时间戳选项

    一.简介 TCP时间戳选项会在TCP包头增加12个字节,以一种比重发超时更精确的方法来启用对RTT 的计算.   二.作用 ) TCP时间戳位于TCP选项中,kind=:lenth=:data由tim ...

  8. vim自定义配色方案,图文并茂

    1.先上图                                 下面是tcpdump的源码.颜色根据自己的喜好配置,我比较喜欢亮的颜色,看的清楚! 2.下载辅助配置文件           ...

  9. Snowflake weakness and type2 fact table

    DimProduct DimSubcategory Dimcategory productpk subcategorypk categorypk sku subcategoryName categor ...

  10. [转]jQuery Popup Login and Contact Form

    本文转自:http://www.formget.com/jquery-popup-form/ Pop up forms are the smart way to present your site. ...