鱼C论坛

 找回密码
 立即注册
查看: 1400|回复: 3

[已解决]python 编程题

[复制链接]
发表于 2021-9-21 05:14:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
There are 68 topics, the day of the
test they will pick 5 of them randomly and she will have to choose 1 of them.
Aina wants to know how many topics she needs to study to have at least an
80% probability of passing.
最佳答案
2021-9-21 12:01:56
本帖最后由 qq1151985918 于 2021-9-21 15:11 编辑

数学不好,结果是 19 对吗?
  1. def A(down, up):
  2.     if down < up:
  3.         raise ValueError("function A(X, Y) -> X should not be less than Y")
  4.     multiply = 1
  5.     for i in range(down, down-up, -1):
  6.         multiply *= i
  7.     return multiply


  8. def C(down, up):
  9.     if down < up:
  10.         raise ValueError("function C(X, Y) -> X should not be less than Y")
  11.     return A(down, up) / A(up, up)


  12. def res(t_nums, p_nums, p):
  13.     for i in range(1, t_nums+1):
  14.         percent = 1 - C(t_nums-i, p_nums) / C(t_nums, p_nums)
  15.         if percent >= p:
  16.             return i
  17.         

  18. if __name__ == "__main__":
  19.     topic_nums = 68
  20.     pick_nums = 5
  21.     probability = 0.8
  22.     print(res(topic_nums, pick_nums, probability))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-21 10:15:03 | 显示全部楼层
你在考别人英文吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-21 12:01:56 | 显示全部楼层    本楼为最佳答案   
本帖最后由 qq1151985918 于 2021-9-21 15:11 编辑

数学不好,结果是 19 对吗?
  1. def A(down, up):
  2.     if down < up:
  3.         raise ValueError("function A(X, Y) -> X should not be less than Y")
  4.     multiply = 1
  5.     for i in range(down, down-up, -1):
  6.         multiply *= i
  7.     return multiply


  8. def C(down, up):
  9.     if down < up:
  10.         raise ValueError("function C(X, Y) -> X should not be less than Y")
  11.     return A(down, up) / A(up, up)


  12. def res(t_nums, p_nums, p):
  13.     for i in range(1, t_nums+1):
  14.         percent = 1 - C(t_nums-i, p_nums) / C(t_nums, p_nums)
  15.         if percent >= p:
  16.             return i
  17.         

  18. if __name__ == "__main__":
  19.     topic_nums = 68
  20.     pick_nums = 5
  21.     probability = 0.8
  22.     print(res(topic_nums, pick_nums, probability))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-22 09:49:53 | 显示全部楼层
本帖最后由 小圣呀 于 2021-9-22 09:54 编辑
  1. import random as r

  2. dic = {i:0 for i in range(1,69)}

  3. for study in range(1,69):

  4.     num = 0
  5.     count = 0
  6.     topic_study = r.sample(range(68),k=study)

  7.     while num < 10000:
  8.         topic_test = r.sample(range(68),k=5)
  9.         for topic in topic_test:
  10.             if topic in topic_study:
  11.                 count += 1
  12.                 break            
  13.         num += 1

  14.     dic[study] = count

  15. for key,value in dic.items():  
  16.   print("Study "+str(key)+" topics "+str(value)+" pass")
复制代码


代码列举了 学习的topic从1个到68个,在10000次重复测试中能够通过的次数,结果如下:(所以大概9次就有一半以上的可能性通过,19次就有80%)

Study 1 topics 690 pass
Study 2 topics 1438 pass
Study 3 topics 2052 pass
Study 4 topics 2682 pass
Study 5 topics 3246 pass
Study 6 topics 3762 pass
Study 7 topics 4342 pass
Study 8 topics 4790 pass
Study 9 topics 5224 pass
Study 10 topics 5642 pass
Study 11 topics 5942 pass
Study 12 topics 6354 pass
Study 13 topics 6680 pass
Study 14 topics 6962 pass
Study 15 topics 7341 pass
Study 16 topics 7485 pass
Study 17 topics 7690 pass
Study 18 topics 7939 pass
Study 19 topics 8225 pass
Study 20 topics 8382 pass
Study 21 topics 8560 pass
Study 22 topics 8666 pass
Study 23 topics 8832 pass
Study 24 topics 8940 pass
Study 25 topics 9090 pass
Study 26 topics 9169 pass
Study 27 topics 9265 pass
Study 28 topics 9325 pass
Study 29 topics 9482 pass
Study 30 topics 9570 pass
Study 31 topics 9577 pass
Study 32 topics 9630 pass
Study 33 topics 9710 pass
Study 34 topics 9750 pass
Study 35 topics 9791 pass
Study 36 topics 9808 pass
Study 37 topics 9821 pass
Study 38 topics 9849 pass
Study 39 topics 9894 pass
Study 40 topics 9908 pass
Study 41 topics 9911 pass
Study 42 topics 9948 pass
Study 43 topics 9936 pass
Study 44 topics 9943 pass
Study 45 topics 9959 pass
Study 46 topics 9981 pass
Study 47 topics 9980 pass
Study 48 topics 9980 pass
Study 49 topics 9986 pass
Study 50 topics 9994 pass
Study 51 topics 9993 pass
Study 52 topics 9996 pass
Study 53 topics 9999 pass
Study 54 topics 10000 pass
Study 55 topics 10000 pass
Study 56 topics 10000 pass
Study 57 topics 9999 pass
Study 58 topics 10000 pass
Study 59 topics 10000 pass
Study 60 topics 10000 pass
Study 61 topics 10000 pass
Study 62 topics 10000 pass
Study 63 topics 10000 pass
Study 64 topics 10000 pass
Study 65 topics 10000 pass
Study 66 topics 10000 pass
Study 67 topics 10000 pass
Study 68 topics 10000 pass
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 05:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表