【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 ...
随机推荐
- DataBase project physical design
DataBase physical design //Table: /*student*/ create table student( id int not null primary key, /*学 ...
- LINUX系统yum安装SVN服务及其配置
待: http://oplinux.com/app/svn/linux-yum-install-svn.html //基础设置及流程 http://files.cnblogs.com/logon/s ...
- Android开发SQLite数据库的创建
package com.example.db; import android.content.Context; import android.database.sqlite.SQLiteDatabas ...
- FPGA市场潜力有几多?
FPGA市场未来成长潜力 本文来源:DIGITIMES 2014年FPGA市场规模为52.7亿美元,据Green Mountain Outlook报导,研调机构Global Market Insigh ...
- MATLAB01
在命令行窗口输入edit就会进入代码编写区,编写完毕点击运行后会先进行保存,然后再执行代码,保存时候一定要以英文开头. 数组 创建矩阵: 函数名 描述 zero(m,n) 创建m行n列全零矩阵 one ...
- Linux_LVM Couldn't find device with uuid
Linux LVM commands result in Couldn't find device with uuid Couldn't find all physical volumes for v ...
- 中小公司的Java工程师应该如何逆袭冲进BAT?
(1)80% Java工程师都有的迷茫 这篇文章,跟大家聊一聊很多很多很多人问我的一个问题:中小公司的Java工程师应该如何规划准备,才能跳槽进入BAT这类一线互联网公司? 之所以我用了三个 “很多” ...
- 解决jenkins拉取报告没有样式的问题(还没试过)
来源: https://testerhome.com/topics/9476 对于测试报告来说,除了内容的简洁精炼,样式的美观也很重要.常用的做法是,采用HTML格式的文档,并搭配CSS和JS,实现自 ...
- java.输入水果的编号,求它对应的单价
总结:可以if-else 循环或switch循环 package com.b; import java.util.Scanner; /*以下4种水果的单价分别是3.00元/公斤,2.50元/公斤,4. ...
- Vue.js:监听属性
ylbtech-Vue.js:监听属性 1.返回顶部 1. Vue.js 监听属性 本章节,我们将为大家介绍 Vue.js 监听属性 watch,我们可以通过 watch 来响应数据的变化: 实例 & ...