HDU 5187】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=5187 Problem Description 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 wa…
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5187 bc(中文): http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=571&pid=1002 题解: 求(2^n-2)%p,题目看错,一天都没什么思路,冷静一下.. 代码: #include<iostream> #include<cstring> #include<cst…
传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 575    Accepted Submission(s): 181 Problem Description As one of the most powerful brushes, zhx is required to give his juniors…
题目分析如果n=1,答案是1,否则答案是2n−2. 证明:ai肯定是最小的或者最大的.考虑另外的数,如果它们的位置定了的话,那么整个序列是唯一的. 那么ai是最小或者最大分别有2n−1种情况,而整个序列单调增或者单调减的情况被算了2次,所以要减2. 要注意的一点是因为p>231,所以要用快速乘法.用法与快速幂相同.如果直接乘会超过long long范围,从而wa掉. 快速幂+快速乘法 #include<cstdio>#include<cstring>#include<c…
zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 448    Accepted Submission(s): 147 Problem Description As one of the most powerful brushes, zhx is required to give his juniors n p…
就是以那个ai为分水岭,左边和右边都分别是单调增或单调减如图         就这四种情况,其中头两种总共就是两个序列,也就是从头到尾递增和从头到尾递减.         后两种方式就是把序列中德数分为左右两派,分完以后左右两边各自内部的排法就已经确定了,至于ai早就确定了(不是全局最大就是全局最小),而除了ai的每一个数都有选择在左或是在右两种选择,所以是2^(n-1),总共就是2^n,而这里包括了前两种的方案,所以要-4,最终应有2^n-2种.         看数据范围就知道要用快速幂,不…
zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1867    Accepted Submission(s): 596 Problem Description As one of the most powerful brushes, zhx is required to give his juniors n p…
超简单的公式题(2^n-2).不过,要过可不容易,因为会爆64位,所以,可以使用快速乘法. #include <iostream> #include <cstdio> #include <algorithm> #define LL unsigned __int64 using namespace std; LL n,p; LL mul(LL x,LL m,LL p)///???? { LL re=; while(m){ ){ re=(re+x)%p; } x=(x+x)…
Problem Description 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 the…
zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3835    Accepted Submission(s): 1255 Problem Description As one of the most powerful brushes, zhx is required to give his juniors n…