LeetCode 458.Poor Pigs
来源:互联网 发布:西宁seo 编辑:程序博客网 时间:2024/06/05 16:02
这一题感觉更像是数学题
题目要求如下
There are 1000 buckets, one and only one of them contains poison, the
rest are filled with water. They all look the same. If a pig drinks
that poison it will die within 15 minutes. What is the minimum amount
of pigs you need to figure out which bucket contains the poison within
one hour.Answer this question, and write an algorithm for the follow-up general
case.Follow-up:
If there are n buckets and a pig drinking poison will die within m
minutes, how many pigs (x) you need to figure out the “poison” bucket
within p minutes? There is exact one bucket with poison.
自己的思维很局限,看到大神的解释不得不膜拜
https://discuss.leetcode.com/topic/67666/another-explanation-and-solution
解法很简单,如下
class Solution { public int poorPigs(int buckets, int minutesToDie, int minutesToTest) { int pigs=0; while(Math.pow(minutesToTest/minutesToDie+1,pigs)<buckets){ pigs+=1; } return pigs; }}
- LeetCode 458. Poor Pigs
- 【leetcode】458. Poor Pigs
- Leetcode 458. Poor Pigs
- [Leetcode] 458. Poor Pigs
- leetcode 458. Poor Pigs
- LeetCode 458.Poor Pigs
- LeetCode 458.poor pigs
- leetcode 458. Poor Pigs
- leetcode 458. Poor Pigs
- leetcode- Add to List 458. Poor Pigs
- [LeetCode]Poor Pigs
- [LeetCode] Poor Pigs
- 458. Poor Pigs
- 458. Poor Pigs
- 458. Poor Pigs
- 458. poor pigs
- 458. Poor Pigs
- 每日一练之poor pigs【leetcode No.458】——猪测毒问题
- PHP学习笔记5-PHP-AJAX请求、文件上传、验证码
- netty中引入spring-boot
- 8月19号CCPC——The Karting(未解决)
- 我的微服务之路
- PHP学习笔记5-PHP-AJAX请求、文件上传、验证码
- LeetCode 458.Poor Pigs
- 【剑指offer】面试题 40:最小的 k 个数
- hpuoj【1061】路旁的树【模拟】&&【标记数组的运用】
- Python 函数(6)
- [Spring] Could not autowire field 异常的一种可能原因
- 练习1-6
- sort 算法小结
- 行人重识别相关技术
- Gensim简介(提取语义主题)