【HDU5187】zhx's contest
【问题描述】
作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题。zhx认为第i道题的难度就是i。他想要让这些题目排列起来很漂亮。
zhx认为一个漂亮的序列{ai}下列两个条件均需满足。
1:a1..ai是单调递减或者单调递增的。
2:ai..an是单调递减或者单调递增的。
他想你告诉他有多少种排列是漂亮的。因为答案很大,所以只需要输出答案模p之后的值。
【题解】
对于整段序列单调增或减,就2种情况。
对于先增后减或先减后增:确定一个序列中的最小值(最大值),其他的要么在左边,要么在右边,有2^(n-1)*2种
而在这2^n种情况中重复计算了单调增或减得情况2次。
所以答案就是2^n-2
由于数据范围很大,不能直接快速幂,需要用到快速乘。
/*************
HDU 5187
by chty
2016.11.1
*************/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,mod;
ll mul(ll x,ll y) {return ((x*y-(ll)(((long double)x*y+0.5)/mod)*mod)%mod+mod)%mod;}//一行快速乘
ll fast(ll a,ll b){ll ans=;for(;b;b>>=,a=mul(a,a))if(b&)ans=mul(ans,a);return ans;}//一行快速幂
int main()
{
while(~scanf("%lld%lld",&n,&mod))
{
if(n==) printf("%lld\n",n%mod);
else printf("%lld\n",(fast(,n)+mod-)%mod);
}
return ;
}
【HDU5187】zhx's contest的更多相关文章
- 【HDU5187】contest
真的没有什么会写的东西了QAQ 原题: As one of the most powerful brushes, zhx is required to give his juniors n probl ...
- 【AtCoder】AtCoder Grand Contest 035 解题报告
点此进入比赛 \(A\):XOR Circle(点此看题面) 大致题意: 给你\(n\)个数,问是否能将它们摆成一个环,使得环上每个位置都是其相邻两个位置上值的异或值. 先不考虑\(0\),我们假设环 ...
- 【POJ】2187 Beauty Contest(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
- 【AtCoder】Tenka1 Programmer Contest 2019
Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...
- 【leetcode】544. Output Contest Matches
原题 During the NBA playoffs, we always arrange the rather strong team to play with the rather weak te ...
- 【AtCoder】M-SOLUTIONS Programming Contest
M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...
- 【LeetCode】544. Output Contest Matches 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...
- 【AtCoder】Yahoo Programming Contest 2019
A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...
- 【AtCoder】Tenka1 Programmer Contest
C - 4/N 列出个方程枚举解一下 #include <bits/stdc++.h> #define fi first #define se second #define pii pai ...
随机推荐
- (转) Myisam和Innodb索引实现的不同(存储结构)
转自 : https://blog.csdn.net/donghaixiaolongwang/article/details/60751543
- MyBatis对多关系:显示该用户的所有角色
只要在一边的UserMapper.xml 配置好就可以了 <?xml version="1.0" encoding="UTF-8" ?> <! ...
- bulkcopy实现批量插入与更新
public static void UpdateData<T>(List<T> list, string TabelName) { DataTable dt = new Da ...
- phpcmsV9搜索分页数量
phpcmsV9搜索结果自定义控制分页条数,具体方法: 打开搜索模型文件夹phpcms/modules/search/index.php, 找到第85行: $result = $this->db ...
- Python之namedtuple源码分析
namedtuple()函数根据提供的参数创建一个新类,这个类会有一个类名,一些字段名和一个可选的用于定义类行为的关键字,具体实现如下 namedtuple函数源码 from keyword impo ...
- django中的locale()函数
就是可以将函数中的变量与其对应的值,自动包裹成字典传到静态页面 参考链接:http://www.jb51.net/article/69558.htm
- FastAdmin 后台 UserRule 勾选不完整 Bug 修复
FastAdmin 后台 UserRule 勾选不完整 Bug 修复 当用户权限的级选择时出现有部分没有选中. 修复来自在 qmit 1 public static function getTreeL ...
- Oracle Database 12.2新特性详解
在2015年旧金山的Oracle OpenWorld大会上,Oracle发布了Database 12.2的Beta版本,虽然Beta版本只对部分用户开放,但是大会上已经公布了12.2的很多重要的新特性 ...
- 自定义标签2.x
2.x只需要继承SimpleTagSupport 1.x 输出流 JspWriter out = pageContext.getOut(); 2.x 输出流 JspWriter out = get ...
- 在 windows7 中使用 vs2003 时,“在文件中查找”导致无响应的问题
解决 Win7 32bit/64bit环境下,在使用VS2003的查找功能时,会导致VS2003无响应. 解决方法:找到VS2003的安装目录,修改"...\Microsoft Visual ...