# 458. Poor Pigs 可怜的小猪

@TOC

## # 题目描述

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.

## # 解题方法

``````1    2   3   4   5

6    7   8   9  10

11  12  13  14  15

16  17  18  19  20

21  22  23  24  25
``````

``````class Solution(object):
def poorPigs(self, buckets, minutesToDie, minutesToTest):
"""
:type buckets: int
:type minutesToDie: int
:type minutesToTest: int
:rtype: int
"""
tests = minutesToTest / minutesToDie + 1
pigs = 0
while tests ** pigs < buckets:
pigs += 1
return pigs
``````

## # 日期

2018 年 7 月 17 日 —— 连天大雨，这种情况很少见，但是很舒服 2018 年 11 月 19 日 —— 周一又开始了