【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 ...
随机推荐
- EasyPlayer实现Android MediaMuxer录像MP4(支持G711/AAC/G726音频)
本文转自EasyDarwin开源团队John的博客:http://blog.csdn.net/jyt0551/article/details/72787095 Android平台的MediaMuxer ...
- matlab批量转化img到gray
path = 'D:\宝贝儿数据集\COIL-3D\coil-100\'; save_path = 'D:\宝贝儿数据集\COIL-3D\coil-100-gray\'; file=dir([path ...
- R 语言赋值运算符:`<-` , `=`, `<<-`
<- 与 = 间的区别 <- 与 = 在大部分情况下是应该可以通用的.并且,相对于 <<- 运算符,它们的赋值行为均在它们自身的环境层(environment hierarch ...
- (六)HTML5立方体动画设置
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 深入理解java虚拟机-第三章
1.概述 2.对象已死吗? 引用计数器 给对象添加一个引用计数器,每当有引用时,计数器加1,引用失效时,计数器减1:任何时刻计数器为0的对象就是不可能再被使用的. 若对象是循环引用,则无法处理.JVM ...
- Laravel 5使用Laravel Excel实现Excel/CSV文件导入导出的功能详解
1.简介 本文主要给大家介绍了关于Laravel 5用Laravel Excel实现Excel/CSV文件导入导出的相关内容,下面话不多说了,来一起看看详细的介绍吧. Laravel Excel 在 ...
- 【转】eclipse + Pydev 配置Python开发环境
原文网址:http://www.cnblogs.com/dflower/archive/2010/05/13/1734522.html 1. 下载并安装python,由于3.1版本貌似存在很多兼容问题 ...
- ODBC CRecordSet访问
一.概述 ODBC 是一种使用SQL 的程序设计接口.使用ODBC 让应用程序的编写者避免了与数据源相联的复杂性.这项技术目前已经得到了大多数DBMS 厂商们的广泛支持. Microsoft Deve ...
- lnmp centos7 memcache服务器端 和 memcache memcached扩展的安装
在项目开发的时候有用到memcache,自己在本地需要搭建一个memcache环境,用于开发和测试; wget http://www.memcached.org/files/memcached-1.5 ...
- java代码-----------java中的windowAdapter的实例
总结:我知道他是一专多能型.很优秀~~~~~~~~~~~.好幸福啊 package com.a.b; import java.awt.Color; import java.awt.event.Wind ...