【leetcode】1227. Airplane Seat Assignment Probability
题目如下:
npassengers board an airplane with exactlynseats. 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-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- zabbix 4.0版本
Zabbix 4.0 最高版本是4.2 1.什么是zabbix及优缺点(对比cacti和nagios) zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速 ...
- Linux 的简单命令以及在idea中配置码云
Linux 的简单命令: ls(list)功能:列出目录内容 cd(change directory)功能:切换目录 touch 1.txt 在当前目录创建一个文件1.txt clear:清除屏幕 p ...
- DSP28335 GPIO学习
根据网络资料以及以下两篇博客整理 http://blog.sina.com.cn/s/blog_86a6035301017rr7.html http://blog.csdn.net/hmf123578 ...
- 应用安全 - 中间件 - IIS - 漏洞 - 汇总
简介 支持协议 HTTP HTTP/2 HTTPS FTP FTPS SMTP NNTP等 支持操作系统 NT/2000/XP Professional/Server 2003及后续版本(XP Hom ...
- 事务与Mysql隔离级别
事务 定义: 比如ABCD四个业务,作为一个事务,他们要么一起都执行完毕,要么都不执行.(只要有一个不成功,那么所有的都不可以成功) 四个特性 ACID 原子性(Atomicity) 整个事务中的所有 ...
- Mac OS X 11中的/usr/bin 的“Operation not permitted”
更新了 Mac OS X 11后发现,MacVim 不再能够通过Terminal用命令打开了. mvim hello.txt 于是尝试将 mvim 重新复制到/usr/bin/中去 sudo cp - ...
- CM金丝雀Canary报错
参考: https://www.cnblogs.com/barneywill/p/10400788.html CM金丝雀Canary报错 1 HDFS 金丝雀Canary 测试无法为 /tmp/.cl ...
- POJ - 1251 Jungle Roads (最小生成树&并查集
#include<iostream> #include<algorithm> using namespace std; ,tot=; const int N = 1e5; ]; ...
- python笔记——dict和set
学习廖雪峰python3笔记_dict和set dict__介绍 dict --> dictionary(字典)--> python内置 --> 使用键-值(key-value)存储 ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...