2014-03-19 06:40

题目:有20瓶药,其中19瓶装的都是1.0克的药片,只有1瓶装了1.1克的药。给你一个能称出具体克数的电子秤,只允许你称一次,怎么找出那瓶不一样的?

解法:如果药片管够,从每个瓶子里取出数量各不相同的药片,根据质量的总和减去“期望的”质量总和,就知道哪瓶有问题了。

代码:

 // 6.1 There are 20 bottles of pills, all of which have pills of 1g, except one with 1.1g.
// Given a balance that can provides exact measurement, can you devise a method to find out the special bottle with just one try?
// Answer:
// If you pick n[i] pills from bottle i, the total weight should be sigma(n[i] * 1.0).
// But there is one with 1.1g pills, that would cause a little deviation to the sum.
// For example, if we pick i pills from bottle i, the sum should be (20 + 1) * 20 / 2 = 210.
// The real weight w should be greater than 210, (w - 210) / (1.1 - 1.0) will be the number.
int main()
{
return ;
}

最新文章

  1. 【Java EE 学习 48】【Hibernate学习第五天】【抓取策略】【二级缓存】【HQL】
  2. Memcache笔记03-php操作Memcached
  3. Android Studio-AndroidStudio目录结构
  4. Matlab:max函数
  5. A javascript library providing cross-browser, cross-site messaging/method invocation. http://easyxdm.net
  6. 使用jxl.jar操作Excel
  7. wireshark设置抓服务器的包
  8. repeater一个简单的用法例子
  9. ArcGIS教程:创建特征
  10. iOS 力学动画生成器UIKit Dynamics 之碰撞效果解说
  11. iOS学习——iOS项目Project 和 Targets配置详解
  12. freemarker中的round、floor和ceiling数字的舍入处理(十七)
  13. Spring MVC的handlermapping之BeanNameUrlHandlerMapping初始化
  14. 从1....n中随机输出m个不重复的数
  15. liteos简介(一)
  16. 将python2代码转为python3
  17. 19. Remove Nth Node From End of List (JAVA)
  18. STL::sort函数实现
  19. Tomcat+Redis+Nginx实现session共享(Windows版)
  20. 用Visual C#创建Windows服务程序

热门文章

  1. 笨办法学Python(四)
  2. DataGrid 样式
  3. jmter安装配置
  4. Javascript作业—取字符串的第一个只出现一次的字母
  5. OpenCV视觉库
  6. UVA 12345 Dynamic len(set(a[LR]))
  7. POJ-1469 COURSES---二分图最大匹配--匈牙利算法
  8. nodejs的一些概念
  9. linq 和 lmabda 表达式 的用法 和优劣 转自 农码一生
  10. 使用Git操作码云