zoukankan      html  css  js  c++  java
  • LeetCode 458. Poor Pigs

    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.

    class Solution {
    public:
        int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
            int t = minutesToTest/minutesToDie+1, i;
            for(i=0; pow(t,i)<buckets; i++) ;
            return i;
        }
    };
    
  • 相关阅读:
    单例 与 static
    ActiveMQ 核心概念
    Jconsole
    死锁
    document write & close
    java.nio.Buffer
    Java 线程控制(输出奇偶数)
    exist & in
    命运
    Super Jumping! Jumping! Jumping!
  • 原文地址:https://www.cnblogs.com/A-Little-Nut/p/10067098.html
Copyright © 2011-2022 走看看