【HDU5187】contest
真的没有什么会写的东西了QAQ
原题:
As one of the most powerful brushes, zhx is required to give his juniors n problems.
zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful way.
zhx defines a sequence {ai} beautiful if there is an i that matches two rules below:
1: a1..ai are monotone decreasing or monotone increasing.
2: ai..an are monotone decreasing or monotone increasing.
He wants you to tell him that how many permutations of problems are there if the sequence of the problems' difficulty is beautiful.
zhx knows that the answer may be very huge, and you only need to tell him the answer module p.
一句话题意:
求有多少种n排列单峰或单调答案膜p
1<=n,p<=1e18
恩
n个数里选最最大放在第i个位置,选i-1个数放前面并递增,剩下的放后面并递减,这样有c(i-1,n)种
(注意不能简单地挑i个数放前面剩下的放后面,一定要先有一个最大/小的数在峰上
所有的i加起来就有Σ_{i=0}^{n-1}c(i,n)=2^(n-1)种
先递减再递增同理,所以方案数*2=2^n种
全部递增和全部递减多算了一遍,减2,最后答案是2^n-2
因为膜数很大所以快速幂的同时快速乘
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long
int rd(){int z=,mk=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')mk=-; ch=getchar();}
while(ch>=''&&ch<=''){z=(z<<)+(z<<)+ch-''; ch=getchar();}
return z*mk;
}
ll n,m;
ll mtp(ll x,ll y){
ll bs=x,z=;
while(y){ if(y&) z=(z+bs)%m; bs=(bs+bs)%m; y>>=;}
return z;
}
ll qcp(ll x,ll y){
ll bs=x,z=;
while(y){ if(y&) z=mtp(bs,z); bs=mtp(bs,bs); y>>=;}
return z;
}
int main(){freopen("ddd.in","r",stdin);
while(scanf("%I64d%I64d",&n,&m)!=EOF){
if(n==){ printf("%I64d\n",n%m); continue;}
printf("%I64d\n",(qcp(,n)-+m)%m);
}
return ;
}
【HDU5187】contest的更多相关文章
- 【HDU5187】zhx's contest
[问题描述] 作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足 ...
- 【CF725D】Contest Balloons(贪心,堆)
题意:acm队伍可以得气球,相同气球数是一个排名.每个队伍有一个气球数上限,如果该队伍的气球数大于上限 该队伍被淘汰.给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名. (2 ≤ n ≤ 3 ...
- 【枚举】Southwestern Europe Regional Contest H - Sheldon Numbers
https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件 ...
- 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...
- 【LeetCode Weekly Contest 26 Q3】Friend Circles
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/friend-circles/ [题意] 告诉你任意两个 ...
- 【LeetCode Weekly Contest 26 Q2】Longest Uncommon Subsequence II
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...
- 【LeetCode Weekly Contest 26 Q1】Longest Uncommon Subsequence I
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/longest-uncommon-subsequence ...
- 【LeetCode】从contest-21开始。(一般是10个contest写一篇文章)
[LeetCode Weekly Contest 29][2017/04/23] 第17周 Binary Tree Tilt (3) Array Partition I (6) Longest Lin ...
- 【37.74%】【codeforces 725D】Contest Balloons
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 关于ComponentOne For WinForm 的全新控件 – DataFilter数据切片器(Beta)
概述 数据切片器在电子商务网站上很常见 - 它们可以帮助用户快速过滤所选商品,并且所有过滤选项都可以在一个地方使用,通常包含核心控件类型为:清单,范围栏和单选按钮等.在ComponentOne For ...
- WEB 前端插件整理
Vs Code 系统插件 #1 Bracket Pair Colorizer 让括号拥有独立的颜色,易于区分.可以配合任意主题使用. #2 Code Runner 非常强大的一款插件,能够运行多种语言 ...
- LINQ之路12:LINQ Operators之数据转换(Projecting)
本篇继续LINQ Operators的学习,这里我们讨论的是数据转换的两种方式:Select和SelectMany,看似简单常用的两种运算符,却也大有讲究.我们会在本篇详细介绍他们的使用方式和适用的场 ...
- 将nginx添加至service服务
一.问题描述: 无法用service命令启动nginx 二.问题分析: /etc/init.d/目录下缺少nginx默认启动脚本 三.问题解决: 在/etc/init.d/路径下添加脚本文件,名称为n ...
- QT 设置应用程序名称和主窗口标题
1.设置应用程序名称 在工程文件.pro文件中,修改Target为想设置的名称 TARGET = MXEditer 2.设置主窗口标题,在main文件中,我的主窗口是MainWindow. int m ...
- vim必备
1. 复制 将vim中整个文件内容复制到系统剪贴板--gg"+yG 2. 格式化 缩进格式化代码--gg=G
- flex外包团队—北京动点软件:推荐一本不错的Flex书籍
内容介绍:Ready to put your ActionScript 3 skills to work on mobile apps? This hands-on book walks you th ...
- mysql57 centos7 使用
####### yum repository install #######mysql yum repo http://repo.mysql.com/wget http://repo.mysql.co ...
- 《WAP团队》作业四——基于原型的团队项目需求调研与分析
基于原型的团队项目需求调研与分析 本项目是一个家教系统的实现,随着时代的进步,现今已经进入信息技术时代,越来越多的人注意到了教育的重要性.家长对于孩子的学习提高注意力,大家都不想自己的孩子输在起跑线上 ...
- 修改host文件——mac
打开终端 在终端terminal中输入sudo vi/etc/hosts sudo与vi之间有一个空格 上一步输入完成之后按回车键,如果当前用户账号有密码,则在按完之后会提示输入密码,此时输入当前账户 ...