题目如下:

n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of passengers will:

  • Take their own seat if it is still available,
  • Pick other seats randomly when they find their seat occupied

What is the probability that the n-th person can get his own seat?

Example 1:

Input: n = 1
Output: 1.00000
Explanation: The first person can only get the first seat.

Example 2:

Input: n = 2
Output: 0.50000
Explanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).

Constraints:

  • 1 <= n <= 10^5

解题思路:我计算了n=3,4,5时的概率,发现都是0.5,所以就有了一个大胆的猜想,除了n=1之外,其他的概率都是0.5。

代码如下:

class Solution(object):
def nthPersonGetsNthSeat(self, n):
"""
:type n: int
:rtype: float
"""
if n == 1 : return float(1)
return 0.50000

最新文章

  1. collectionView,tableView的细节处理
  2. Hololens开发笔记之使用Unity开发一个简单的应用
  3. ES6入门之Symbol
  4. big data vs HPC
  5. CentOS 如何使用第三方软件库-EPEL与RPMForge、RPMFusion软件库
  6. ISP PIPLINE (十二) Sharpening
  7. Html5 localStorage 缓存
  8. Json对象遍历
  9. [ISSUE] [Centos] Centos Start Nginx Show: Failed to start nginx.service:unit not found
  10. Linux 内核里的数据结构:红黑树(rb-tree)
  11. Windows系统下oracle数据库每天定时备份
  12. Mysql学习(一)添加一个新的用户并用golang操作Mysql
  13. nginx简单学习(tomcat)
  14. hdu 5051 找规律?+大trick
  15. VMware 14 的永久许可密钥
  16. Jackson基础
  17. Vue使用SCSS进行模块化开发
  18. Spring里的aop实现方式和源码分析
  19. 每日一Vim(1)
  20. nginx-rtmp-module--------------WIKI

热门文章

  1. P4878 [USACO05DEC] 布局
  2. Ubuntu环境配置机器安装驱动
  3. vue2.X + HTML5 plus 拍照和调用设备相册 另附 图片转base64和压缩图片方法
  4. navicat连接 mysql报错1251解决方案
  5. HDU 1159 Common Subsequence (动态规划、最长公共子序列)
  6. HDU 2809 God of War (状压DP)
  7. 微服务理论之二:面向微服务架构与传统架构、SOA对比,以及云化对比
  8. 匿名函数lambda和map函数
  9. Java编程思想读书笔记 第一章 对象导论
  10. Java 迪杰斯特拉算法实现查找最短距离