https://leetcode.com/problems/poor-pigs/

package com.company;

class Solution {
// 下面第二种做法貌似是OJ原来的做法,但是是错误的
// 看了这个解答 https://discuss.leetcode.com/topic/66856/major-flaw-in-current-algorithm-fixed
public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
// 有5种状态
int circle = minutesToTest / minutesToDie + ;
int ret = ;
long num = ;
while (num < buckets) {
num *= circle;
ret++;
}
return ret;
}

// 以下答案不太对
public int poorPigs2(int buckets, int minutesToDie, int minutesToTest) {
if (minutesToDie == ) {
return ;
}
int circle = minutesToTest / minutesToDie;
if (circle == ) {
return ;
}
int batch = (buckets + (circle - )) / circle; int ret = ;
long num = ;
while (num < batch) {
num *= ;
ret++;
}
if (num == batch && circle != ) {
return ret + ;
}
else {
return ret;
}
}
} public class Main { public static void main(String[] args) throws InterruptedException { System.out.println("Hello!");
Solution solution = new Solution(); // Your Codec object will be instantiated and called as such:
int ret = solution.poorPigs(, , );
System.out.printf("ret:%d\n", ret); System.out.println(); } }

最新文章

  1. ES6笔记(3)-- 解构赋值
  2. Cordova - 使用Cordova开发iOS应用实战1(配置、开发第一个应用)
  3. WPS文字在表格中打字自动跳动
  4. nyoj 20
  5. Delphi 中的结构体与结构体指针
  6. 用户浏览器关闭cookie处理方法
  7. [C++程序设计]有关形参与实参,及返回值说明
  8. zabbix java api
  9. 385cc412a70eb9c6578a82ac58fce14c md5破解
  10. ArrayList循环遍历并删除元素的常见陷阱
  11. centos 7 Chrony 集群同步时间
  12. mysql实现多实例
  13. 【转】nvidia-smi 命令解读
  14. python测试开发django-52.xadmin添加自定义的javascript(get_media)
  15. 每天一个linux命令:top
  16. chmod语法
  17. 对数组的操作splice() 和slice() 用法和区别
  18. HMM模型学习笔记(前向算法实例)
  19. 查看php-fpm开启的进程数以及每个进程的内存限制
  20. 【Tomcat】部署Web到tomcat的四种方式

热门文章

  1. Spider_Man_6 の Scrapy(未完待续)
  2. Halcon17 Linux 下载
  3. [python][django学习篇][4]django完成数据库代码翻译:迁移数据库(migration)
  4. 2017年浙江工业大学之江学院程序设计竞赛决赛 I: qwb VS 去污棒(可持久化Trie+离线)
  5. centos安装arm交叉工具链后常见的问题解决
  6. Sabota?
  7. AtCoder Regular Contest 075 C D E (暂时)
  8. 转 网络编程学习笔记一:Socket编程
  9. 对/proc和/sys的一些理解
  10. SaltStack 模块学习之拷贝master服务器上文件和目录到minion服务器