bzoj1965: [Ahoi2005]SHUFFLE 洗牌
2016-02-10 01:39
435 查看
链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1965
题意:中文题。。。
分析:一个置换的题。。我们对样例进行简单的分析可知经过一次变换有(1->2,2->4,3->6,4->1,5->3,6->5),然后我们就能发现p[a]=a*2%(n+1)。。然后我们设答案为X即X=p[l],所以有X*(2^m)=l%(n+1)并且2模n+1的逆元为n/2+1,所以我们将等式变换一下就有X=l*(n/2+1)^m%(n+1),然后就只要用快速幂处理这个式子就行了,同时要注意数据是10^10可能乘爆,用快速乘即可。
代码:
#include<map> #include<set> #include<cmath> #include<queue> #include<math.h> #include<cstdio> #include<vector> #include<string> #include<cstring> #include<iostream> #include<algorithm> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N=100010; const int MAX=151; const int MOD1=100000007; const int MOD2=100000009; const double EPS=0.00000001; typedef long long ll; const ll MOD=5000011; const ll INF=10000000010; typedef unsigned long long ull; ll mul(ll a,ll b,ll M) { ll ret=0; for (ll i=b;i;i>>=1,a=(a+a)%M) if (i&1) ret=(ret+a)%M; return ret; } ll qpow(ll a,ll b,ll M) { ll ret=1; for (ll i=b;i;i>>=1,a=mul(a,a,M)) if (i&1) ret=mul(ret,a,M); return ret; } int main() { ll n,m,l,ans; scanf("%lld%lld%lld", &n, &m, &l); ans=l*qpow(n/2+1,m,n+1); printf("%lld\n", (ans+n+1)%(n+1)); return 0; } /* 6 2 3 */
相关文章推荐
- MySQL时间戳转换
- 【Linux命令】grep命令
- 36. Valid Sudoku
- HDU 4508湫湫系列故事――减肥记i-简单的完全背包
- 【Linux命令】crontab命令
- python学习笔记——文件操作
- 【NYOJ】[477]A+B Problem III
- 1012. The Best Rank (25)
- 290. Word Pattern
- HDU 4563 御剑术I(背包)
- HDU 4501 小明系列之买年货(三维背包)
- 【NYOJ】[811]变态最大值
- 1. Two Sum
- 【慕课笔记】U4 多态 第2节 多态中的引用类型转换
- 在PC端实现HTML5-geolocation的一些细节
- 选择
- GSON
- bzoj3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛
- VS2010 Error : Unable to start program Access is denied
- Notes of Python Learning 2/10/2016