传送门:https://www.luogu.org/problemnew/show/CF838D

这道题反正我自己想是毫无头绪,最后还是听了肖大佬的做法。

因为题中说乘客可以从前后门进来,所以我们可以把这n个作为想象成一个环,然后乘客们都从n + 1的位置出发,于是从前后门就变成了顺逆时针。

很容易得出,所有方案为 [2 * (n +1)] ^ m 种,但是这其中包含了不合法方案,所以要减去不合法的情况。那么什么是不合法的情况呢?一个人转了一圈又回到了 n + 1 号的座位,就说明他没有找到位置,所以所有不合法的情况就是走到n + 1的情况。

然后因为每一个座位是一样的,所以走到的合法情况的概率是等价的,都是 (n +1 - m) / (n + 1),所以最终的答案就是 [2 * (n +1)] ^ m * (n +1 - m) / (n + 1)。

化简一下:     2 ^ m * (n +1) ^ (m - 1) * (n +1 - m)

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define enter printf("\n")
#define space printf(" ")
#define Mem(a) memset(a, 0, sizeof(a))
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 6e5 + ;
const ll mod = 1e9 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch))
{
ans = ans * + ch - ''; ch = getchar();
}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} ll n, m; ll quickpow(ll a, ll b)
{
a %= mod;
ll ret = ;
while(b)
{
if(b & ) ret = ret * a % mod;
a = a * a % mod; b >>= ;
}
return ret;
} int main()
{
n = read(); m = read();
write(quickpow((ll), m) * quickpow(n + , m - ) % mod * (n + - m) % mod); enter;
return ;
}

CF838D Airplane Arrangements的更多相关文章

  1. CF838D Airplane Arrangement

    题目描述:https://www.luogu.org/problemnew/show/CF838D(有翻译) (为什么博客园把我刚写的给吞了……orz) 这题当初看的十分懵逼,不过听了肖大佬的做法还是 ...

  2. Codeforces.838D.Airplane Arrangements(思路)

    题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...

  3. codeforces838D - Airplane Arrangements

    太妙啦! 我们把座位摆成一个环,在添加另一个座位,表示坐了这个位置就会有人生气,那么我们现在要求的就是没人坐它的方案数Ans,但是这个并不好求,我们发现对于每个位置,它们的Ans都是一样的,而且Ans ...

  4. 洛谷 P6672 - [清华集训2016] 你的生命已如风中残烛(组合数学)

    洛谷题面传送门 题解里一堆密密麻麻的 Raney 引理--蒟蒻表示看不懂,因此决定写一篇题解提供一个像我这样的蒟蒻能理解的思路,或者说,理解方式. 首先我们考虑什么样的牌堆顺序符合条件.显然,在摸牌任 ...

  5. IndiaHacks 2nd Elimination 2017 (unofficial, unrated mirror, ICPC rules)

    D. Airplane Arrangements time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. Intro to Airplane Physics in Unity 3D – 2017 and 2018

    Info:DescriptionHave you ever wanted to build your own Airplane Physics using the Rigidbody componen ...

  7. Codeforces Round #460 (Div. 2)-C. Seat Arrangements

    C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  8. Codeforces 919 C. Seat Arrangements

    C. Seat Arrangements   time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Security arrangements for extended USB protocol stack of a USB host system

    Security arrangements for a universal serial bus (USB) protocol stack of a USB host system are provi ...

随机推荐

  1. windows下nodejs监听80端口

    windows下nodejs监听80端口时提示端口被占用报错,解决方案如下: 1.cmd---netstat -ano查看是什么程序占用了80端口: 2.控制面板--管理工具--服务--停止 SQL ...

  2. winform窗体 控件 【ListView】

      ListView  表格试图 1.设置视图属性 Details     试图可见 2.设置列      Columns集合 编辑列——  添加列,修改列名 3.添加行数据      Items 集 ...

  3. Android-Binder机制

    http://www.jianshu.com/p/af2993526daf https://www.jianshu.com/u/e347b97e2f0c 上面这篇文章讲得很清楚.以下我的一些理解: 还 ...

  4. Codeforces841B

    B. Godsend time limit per test:2 seconds memory limit per test:256 megabytes input:standard input ou ...

  5. 【学习笔记】--- 老男孩学Python,day6 字典

    详细方法:http://www.runoob.com/python/python-dictionary.html 1. dict 用大括号{} 括起来. 内部使用key:value的形式来保存数据 { ...

  6. 绘图:Matplotlib

    用于绘制一些数据图,同学推荐的,挺好用.非常好的官网文档:http://matplotlib.org/contents.html 0. 安装 可以直接pip install,还有一些依赖就按照提示来吧 ...

  7. web界面 之 登录 (初稿)

    web登录一般注意以下几点: 1)拥有元素:用户名,密码(密码字符显示与隐藏功能),登录按钮,忘记密码链接(忘记用户名链接),注册链接 2)用户体验: •页面显示,光标默认停在第一个输入框 利用htm ...

  8. JavaSE——序列化和反序列化

    序列化: 序列化对应写的操作.(读与写都是站在应用的角度上) 序列化就是一种用来处理对象流的机制,所谓对象流也就是将对象的内容进行流化.可以对流化后的对象进行读写操作,也可将流化后的对象传输于网络之间 ...

  9. Fedora16的双显卡切换问题

    症状:笔记本是Acer 4745G,安装了Fedora16+Win7 x64的双系统,每次开机后,独立显卡的风扇就开始狂转,同时笔记本的发热量极大,左侧出风口简直烫手.... 问题:Acer 4745 ...

  10. 微信小程序开发--模板(template)使用,数据加载,点击交互

    微信小程序视图层提供了 模板(template),可以在模板中定义代码片段,然后在不同的地方调用.结果在数据渲染那懵逼了.按照官网上对模板的说明和对数据的加载. 1.定义模板 使用name属性,作为模 ...