【leetcode】1227. Airplane Seat Assignment Probability
题目如下:
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
【leetcode】1227. Airplane Seat Assignment Probability的更多相关文章
- 【leetcode】688. Knight Probability in Chessboard
题目如下: On an NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exa ...
- 【LeetCode】代码模板,刷题必会
目录 二分查找 排序的写法 BFS的写法 DFS的写法 回溯法 树 递归 迭代 前序遍历 中序遍历 后序遍历 构建完全二叉树 并查集 前缀树 图遍历 Dijkstra算法 Floyd-Warshall ...
- 【LeetCode】380. Insert Delete GetRandom O(1) 解题报告(Python)
[LeetCode]380. Insert Delete GetRandom O(1) 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxu ...
- 【LeetCode】849. Maximize Distance to Closest Person 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- char* a = "abc" 和 char a[] = "abc" 之间的区别
char* a = "abc"; 声明了一个字符类型的指针a,并为它赋值初始值为"abc",a的值是字符串"abc"的首地址[第一个字符的地 ...
- How do I add a Foreign Key Field to a ModelForm in Django?
What I would like to do is to display a single form that lets the user: Enter a document title (from ...
- USACO1.6 Healthy Holsteins【dfs/bfs 爆搜】
题目传送门 饲料种数只有15 枚举每种选或不选一共也就只有$2^{15}=32768$ 爆搜可过觉得bfs要快一些? 但是dfs更方便处理字典序 只需要顺序遍历并且先搞选它的情况就可以了 而且在这种规 ...
- redis学习(三)
如何保障reids的数据安全和性能? 一.持久化选项 1.快照snapshotting 它可以将存在于某一时刻的所有数据都写入硬盘里面. 配置选项示例: save 60 1000 注:从最近一次创 ...
- 第八周课程报告&&实验报告六
Java实验报告 班级 计科一班 学号 20188390 姓名 宋志豪 实验四 类的继承 实验目的 理解异常的基本概念: 掌握异常处理方法及熟悉常见异常的捕获方法. 实验要求 练习捕获异常.声明异常. ...
- deepin之添加右键新建文档选项
deepin之添加右键新建文档选项 虽然Linux系统下所有皆文件,创建各种文件很简单,也很随意,但还是有人讨厌采用先创建空文件再改文件名的方式(比如我),我还是喜欢右键新建一个相应的源文件,可是默认 ...
- 【转帖】AMD:未向合资企业THATIC发放后续芯片设计授权
AMD:未向合资企业THATIC发放后续芯片设计授权 https://www.cnbeta.com/articles/tech/854193.htm 海光和兆芯的CPU 都不靠谱啊. 在台北电脑展(C ...
- [转帖]linux进程管理总结
linux进程管理总结 https://www.cnblogs.com/chenfangzhi/p/10660355.html 高手总结的.. 看出来我是菜逼. 目录 一.进程相关的概念 二.关闭会话 ...
- [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs)
[Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs) 题面 题意:给你一个无向图,1为起点,求生成树让起点到其他个点的距离最小,距离最小 ...
- JS中property与attribute的区别
property与attirbute都是属性的意思,在JS中很容易混淆,但实际上二者有很大的区别.简单来说, property:是DOM中的属性,是JavaScript中的对像 attribute:是 ...