CF838D Airplane Arrangements
传送门: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的更多相关文章
- CF838D Airplane Arrangement
题目描述:https://www.luogu.org/problemnew/show/CF838D(有翻译) (为什么博客园把我刚写的给吞了……orz) 这题当初看的十分懵逼,不过听了肖大佬的做法还是 ...
- Codeforces.838D.Airplane Arrangements(思路)
题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...
- codeforces838D - Airplane Arrangements
太妙啦! 我们把座位摆成一个环,在添加另一个座位,表示坐了这个位置就会有人生气,那么我们现在要求的就是没人坐它的方案数Ans,但是这个并不好求,我们发现对于每个位置,它们的Ans都是一样的,而且Ans ...
- 洛谷 P6672 - [清华集训2016] 你的生命已如风中残烛(组合数学)
洛谷题面传送门 题解里一堆密密麻麻的 Raney 引理--蒟蒻表示看不懂,因此决定写一篇题解提供一个像我这样的蒟蒻能理解的思路,或者说,理解方式. 首先我们考虑什么样的牌堆顺序符合条件.显然,在摸牌任 ...
- 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 ...
- 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 ...
- Codeforces Round #460 (Div. 2)-C. Seat Arrangements
C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 919 C. Seat Arrangements
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
随机推荐
- jsp、css中引入外部资源相对路径的问题
在jsp页面中添加base,可用相对路径: <% String path = request.getContextPath(); String basePath = request.getSch ...
- [javascript] 看知乎学习js事件触发过程
红色箭头代表捕获阶段 蓝色代表目标阶段 绿色代表冒泡阶段 调用元素对象的addEventListener()方法,参数:事件,回调函数,是否捕获(true代表捕获阶段,false代表冒泡阶段,ie浏览 ...
- 【JavaFx教程】第六部分:统计图
第6部分的主题 创建一个统计图显示生日的分布. 生日统计 在AddressApp中所有人员都有生日.当我们人员庆祝他们生日的时候,如果有一些生日的统计不是会更好. 我们使用柱状图,包含每个月的一个条形 ...
- 从实例角度分析java的public、protected、private和default访问权限
一.public 同一个package 1.本类内部 public class A { public int f=1; public void m1() {} public void m2() { f ...
- Java - "JUC"之Condition源码解析
Java多线程系列--“JUC锁”06之 Condition条件 概要 前面对JUC包中的锁的原理进行了介绍,本章会JUC中对与锁经常配合使用的Condition进行介绍,内容包括:Condition ...
- Vue之组件使用(一)
这仅仅是个人为了防止忘记做的笔记而已,仅供参考,有不对的地方请纠正 组件这种东西用来封装多次使用的控件还是很有用处的,我还是挺喜欢这种模式,优化了前端的工作,写个组件也比较简单.下次有时间记录一下样式 ...
- linux_shell_传递参数
在执行shell脚本时可以传递参数: 脚本获取参数的格式为:$0 $1 $2 ...其中$1 为传递的第一个参数 而$0 接受的是./test.sh 这个东西 代码:例: #!/bin/bash ...
- MYSQL一次千万级连表查询优化
概述:交代一下背景,这算是一次项目经验吧,属于公司一个已上线平台的功能,这算是离职人员挖下的坑,随着数据越来越多,原本的SQL查询变得越来越慢,用户体验特别差,因此SQL优化任务交到了我手上. 这个S ...
- SpringBoot —— AOP注解式拦截与方法规则拦截
AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法,所以它有一个专门的编译器用来生成遵守Java字节编码规范的Class文件. SpringBoot中AOP的使用 ...
- 如何启动一个Vue2.x项目
1. cd到工作目录2. npm init -y3. 先查看有没有安装全局的vue-cli,:vue-V,没有的话安装一下:npm install vue-cli4. 创建项目: vue init w ...