查找水在第i个杯子一个金字塔结构的金额?

编程入门 行业动态 更新时间:2024-10-17 16:36:08
本文介绍了查找水在第i个杯子一个金字塔结构的金额?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题被问在一个论坛。有什么建议?

有一个与1杯的水平,2金字塔2级,3个3级等.. 它看起来像这样

1  2 3 4 5 6

每杯有能力C.你从上面倒大号升水。当杯1被填满时,它溢出到杯2,3同样,当它们被填满,杯4和6得到的水只能从2,3 RESP但5得到的水来自两个杯子等。 现在给C和L .Find的水量在第i个杯子?

解决方案

每个玻璃具有的的传入流量的,是的的水量的玻璃,也许有些输出流的(溢)。

如果每个玻璃可以包含1单元的水,你倒15个单位的水,你会得到如下(括号中溢出量):

传入流量= 15,容量= 1 级别1:1(14) 级别2:1(6)1(6) 等级3:1(2)1(5)1(2) 4级:1(1)1(2.5)1(2.5)1(1) 5级:1(0.75)1(1.5)1(0.75)1 6级:0 1 0.375(0.125)1(0.125)0.375 0 7级:0 0 0.0625 0.125 0.0625 0 0

在传入流量的,以第一级是L的传入流量的玻璃 C 上一级研究是翅(C,R),并可以写成:

翅(0,R)= 0 翅片(R + 1,R)= 0 翅片(1,1)= L 翅片(C,R)=个Fout(三 - 1,R - 1)/ 2 +的F out(C,R - 1)/ 2

在的水量的以玻璃为:

A(C,R)=最小值(C,散热片(C,R))

和中的输出流的是:

的F out(C,R)= MAX(0,翅(C,R) - C)

我看不出有什么明显的公式,用于评估 A(C,R)不这样做递归。

要在索引中得到一个行和玻璃的位置,你可以这样做:

指数= R *(R-1)/ 2 + C R =地板((1 + SQRT(8 *指数 - 7))/ 2) C =指数 - R *(R-1)/ 2 (索引从1开始)

This question was asked in a forum. Any suggestions?

There is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on.. It looks something like this

1 2 3 4 5 6

every cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the cups and so on. Now given C and L .Find the amount of water in ith cup ?

解决方案

Each glass has an incoming flow, an amount of water in the glass, and maybe some outgoing flow (overflow).

If each glass can contain 1 unit of water, and you pour 15 units of water, you get the following (overflow amount in parenthesis):

Incoming flow = 15, capacity = 1 Level 1: 1(14) Level 2: 1(6) 1(6) Level 3: 1(2) 1(5) 1(2) Level 4: 1(1) 1(2.5) 1(2.5) 1(1) Level 5: 1 1(0.75) 1(1.5) 1(0.75) 1 Level 6: 0 0.375 1(0.125) 1(0.125) 0.375 0 Level 7: 0 0 0.0625 0.125 0.0625 0 0

The incoming flow to the first level is L. The incoming flow from glass c on level r is Fin(c, r), and could be written as:

Fin(0, r) = 0 Fin(r+1, r) = 0 Fin(1, 1) = L Fin(c, r) = Fout(c - 1, r - 1)/2 + Fout(c, r - 1)/2

The amount of water in that glass is:

A(c, r) = Min(C, Fin(c, r))

And the outgoing flow is:

Fout(c, r) = Max(0, Fin(c, r) - C)

I don't see any obvious formula for evaluating A(c, r) without doing it recursively.

To get from an index to a row and glass position, you can do:

index = r*(r-1)/2 + c r = floor((1 + sqrt(8*index - 7))/2) c = index - r*(r-1)/2 (indexes start with 1)

更多推荐

查找水在第i个杯子一个金字塔结构的金额?

本文发布于:2023-11-29 16:14:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:杯子   金额   金字塔结构

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!