2021 ICPC Asia Taiwan Online Programming Contest

D. Drunk Passenger

链接: 2021icpctaiwan.

Due to COVID-19, social distancing is applied in our daily life to prevent the spread of the disease. It changes our living styles a lot, especially the way of traveling. Now, many carriers cancel non-reserved seats and introduce seating rules to ensure that the distance between any two passengers is long enough.

On your trip to the 2022 ICPC World Finals, you take a flight. The airplane provides n reserved seats to n passengers. The passengers must queue up first; then they board the airplane one by one. You are the last passenger to board, since you are at the end of the queue. Unfortunately, the first passenger is drunk. The drunk passenger randomly goes to another passenger’s seat and then sits there. You may assume the following.

The drunk passenger never takes their own seat.
The probability of any other seat taken by the drunk passenger is uniform.
Luckily, all the other passengers are not drunk. However, they don’t want to move any passenger from a taken seat. If a passenger’s seat has been taken by another passenger when boarding, the passenger would randomly take a vacant seat with equal probability. Otherwise, the passengers just take their own seats.

Please write a program to compute the probability that your seat is taken by another passenger.

思路

在这里插入图片描述

如果给1规定随便坐,可以到1号桌子,那么n号就有1/2概率做到座位上
现在规定做不到座位上,我们可以从上面的式子知道,每一层的概率
(死活,意义不大)都是1/2,因为是随机嘛
然后第一层虚线箭头走不通,那么第一层到达5的死路就没有到达1的
虚线对冲,这个算特殊,
剩下其他的就是不能选择父节点已经选择的点,情况和null一样,我们
通过随便写两个样例得知,除了一和n之外,每一个的都是对称的,
也就是说醉汉选择了2~n-1 ,n能够活下来的情况是一半,那么总
的为 1/2 * ((n-2) /n-1))
再加上如果醉汉选择了n点,n必坐不上他自己的座位
所以结果就是   1/(n -1)  + 1/2 * ((n-2) /n-1)) = n/(2*(n-1)

AC

#include <bits/stdc++.h>
using namespace std;
#define db double

int main()
{
    int n;
    cin>>n;
    db ans = n*1.0/(2*(n-1));
    printf("%.8lf",ans);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.0-0.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值