Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of dividing 8 liters of water into three buckets by php

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of php how to solve the problem of 8-liter water in three buckets, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this php article on how to solve the problem of 8-liter water in three buckets. Let's take a look.

Intelligence problem

There are three 3-liter, 5-liter and 8-liter buckets, of which 8-liter buckets are filled with water, while 3-liter and 5-liter buckets are empty. The three buckets have no scale, and now it is necessary to divide the 8 litres of water in the large buckets into two equal parts, each containing 4 litres of water, with the condition that only these three buckets can be used, and no other auxiliary containers can be used.

"well, yes, it's a classic question."

"however, we can't think about it all. If you don't believe it, please read on."

Answer

"Don't talk too much nonsense, just look at the method."

The first (7 steps)

Fill the 8L bucket with 5L bucket, at this time: 8L bucket is 3L, 5L bucket is 5L, 3L bucket is 0L

Fill the 5L bucket with 3L bucket, at this time: 8L bucket is 3L, 5L bucket is 2L, 3L bucket is 3L

Pour the water from the 3L bucket into the 8L bucket, at this time: 8L bucket is 6L, 5L bucket is 2L, 3L bucket is 0L

Pour the water from the 5L bucket into the 3L bucket, at this time: 8L bucket is 6L, 5L bucket is 0L, 3L bucket is 2L

Pour the water from the 8L bucket into the 5L bucket, at this time: 8L bucket is 1L, 5L bucket is 5L, 3L bucket is 2L

Fill the 5L bucket with 3L bucket, at this time: 8L bucket is 1L, 5L bucket is 4L, 3L bucket is 3L

Pour the water from the 3L bucket into the 8L bucket. At this time, the 8L bucket is 4L, the 5L bucket is 4L, and the 3L bucket is 0L.

The second (8 steps)

Fill the 8L bucket with 3L bucket. At this time: 8L bucket is 5L, 5L bucket is 0L, 3L bucket is 3L.

Pour the water from the 3L bucket into the 5L bucket, at this time: 8L bucket is 5L, 5L bucket is 3L, 3L bucket is 0L

Fill the 8L bucket with the 3L bucket. At this time, the 8L bucket is 2L, the 5L bucket is 3L, and the 3L bucket is 3L.

Fill the 5L bucket with the water in the 3L bucket, then the 8L bucket is 2L, the 5L bucket is 5L, and the 3L bucket is 1L.

Pour the water from the 5L bucket into the 8L bucket, at this time: 8L bucket is 7L, 5L bucket is 0L, 3L bucket is 1L

Pour the water from the 3L bucket into the 5L bucket, at this time: 8L bucket is 7L, 5L bucket is 1L, 3L bucket is 0L

Fill the 8L bucket with the 3L bucket. At this time, the 8L bucket is 4L, the 5L bucket is 1L, and the 3L bucket is 3L.

Pour the water from the 3L bucket into the 5L bucket, at this time: 8L bucket is 4L, 5L bucket is 4L, 3L bucket is 0L

I believe there must be more than two answers. How many answers are there?

With this question in mind, let's design an algorithm.

Problem analysis of human thinking

The key to solving this problem is how to pour water to get a definite 1 liter of water or the space that can hold 1 liter of water.

For example, when 8L bucket or 5L bucket or 3L bucket has 1L water, 4L water can be poured out quickly.

Computer thinking

Exhaustion method

Bucket initial state: 8L buckets are filled with water, 3L and 5L buckets are empty. The final state of the bucket: 3L bucket is empty, 5L and 8L bucket are 4L water each.

Suppose the volume of water in the three buckets in each state is taken as status.

Get $status = array from $status = array (8pj0pl 0).

Of course, there will be some restrictions:

1. Each bucket has a maximum value:

0

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report