Go语言实现Drying Potatoes

描述

引自codewars:
All we eat is water and dry matter.
John bought potatoes: their weight is 100 kilograms. Potatoes contain water and dry matter.
The water content is 99 percent of the total weight. He thinks they are too wet and puts them in an oven - at low temperature - for them to lose some water.
At the output the water content is only 98%.
What is the total weight in kilograms (water content plus dry matter) coming out of the oven?
He finds 50 kilograms and he thinks he made a mistake: “So much weight lost for such a small change in water content!”
Can you help him?
Write function potatoes with
int parameter p0 - initial percent of water-
int parameter w0 - initial weight -
int parameter p1 - final percent of water -
potatoesshould return the final weight coming out of the oven w1 truncated as an int.

分析

这道题,逻辑思路并不难,只不过有一点容易理解错,也就是:水分含量变为98%,参照重量不再是先前的100kg,而是缩水后的包含水分与固体的总重量。

假设缩水后水分重量为x,则:
x / (x + w0 * (100 - p0) / 100) = p1 / 100
x = p1 * w0 * (100 - p0) / (100 * (100 - p1))
缩水后总重量为:
x / (p1 / 100) = w0 * (100 - p0) / (100 - p1)

实现

func Potatoes(p0, w0, p1 int) int {
    return w0 * (100 - p0) / (100 - p1)
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值