【leetcode】1227. Airplane Seat Assignment Probability
2024-10-07 05:03:30
题目如下:
n
passengers board an airplane with exactlyn
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
最新文章
- collectionView,tableView的细节处理
- Hololens开发笔记之使用Unity开发一个简单的应用
- ES6入门之Symbol
- big data vs HPC
- CentOS 如何使用第三方软件库-EPEL与RPMForge、RPMFusion软件库
- ISP PIPLINE (十二) Sharpening
- Html5 localStorage 缓存
- Json对象遍历
- [ISSUE] [Centos] Centos Start Nginx Show: Failed to start nginx.service:unit not found
- Linux 内核里的数据结构:红黑树(rb-tree)
- Windows系统下oracle数据库每天定时备份
- Mysql学习(一)添加一个新的用户并用golang操作Mysql
- nginx简单学习(tomcat)
- hdu 5051 找规律?+大trick
- VMware 14 的永久许可密钥
- Jackson基础
- Vue使用SCSS进行模块化开发
- Spring里的aop实现方式和源码分析
- 每日一Vim(1)
- nginx-rtmp-module--------------WIKI
热门文章
- P4878 [USACO05DEC] 布局
- Ubuntu环境配置机器安装驱动
- vue2.X + HTML5 plus 拍照和调用设备相册 另附 图片转base64和压缩图片方法
- navicat连接 mysql报错1251解决方案
- HDU 1159 Common Subsequence (动态规划、最长公共子序列)
- HDU 2809 God of War (状压DP)
- 微服务理论之二:面向微服务架构与传统架构、SOA对比,以及云化对比
- 匿名函数lambda和map函数
- Java编程思想读书笔记 第一章 对象导论
- Java 迪杰斯特拉算法实现查找最短距离