XTOJ 1243 2016【矩阵快速幂取模】
来源:互联网 发布:壮游科技和塔人网络 编辑:程序博客网 时间:2024/06/04 18:00
2016
Accepted : 100 Submit : 366Time Limit : 2000 MS Memory Limit : 65536 KB2016
Given a
Special Note: The problem is intended to be easy. Feel free to think why the problem is called 2016
if you either:
- find it hard to solve;
- or, solved all the other problems easily.
Input
The input contains at most
The first line contains an integer
The second line contains
The third line contains
(
Output
For each set, a
Sample Input
21 11 220161 11 2
Sample Output
2 33 51 00 1
Source
XTU OnlineJudge原题链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1243
当时做的时候没注意n的范围,矩阵快速幂取模,n对2016取模,具体为什么也还没有想清楚。
剩下的就是模板的事了。
AC代码:
/** * 博客地址:http://blog.csdn.net/hurmishine*/#include <iostream>#include <cstdio>using namespace std;const int maxn=100000+5;struct Matrix{ int m[2][2];};Matrix I={ 1,0, 0,1};Matrix p;Matrix mul(Matrix a,Matrix b){ Matrix ans; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { ans.m[i][j]=0; for(int k=0; k<2; k++) { ans.m[i][j]+=(a.m[i][k]*b.m[k][j])%7; ans.m[i][j]%=7; } } } return ans;}Matrix quick_mod(Matrix a,int p){ Matrix ans=I; Matrix tmp=a; while(p) { if(p&1) ans=mul(ans,tmp); tmp=mul(tmp,tmp); p>>=1; } return ans;}int main(){ char a[maxn]; while(cin>>a) { cin>>p.m[0][0]>>p.m[0][1]>>p.m[1][0]>>p.m[1][1]; int n=0; for(int i=0; a[i]; i++) { n=(n*10+a[i]-'0')%2016; } Matrix ans=quick_mod(p,n); cout<<ans.m[0][0]<<" "<<ans.m[0][1]<<endl; cout<<ans.m[1][0]<<" "<<ans.m[1][1]<<endl; } return 0;}
0 0
- XTOJ 1243 2016【矩阵快速幂取模】
- 矩阵 快速幂取模算法
- 矩阵快速幂取模
- 矩阵快速幂取模
- 快速幂,快速幂取模,矩阵快速幂
- UVA 10689 矩阵快速幂 + 快速幂取模
- 2016湘潭邀请赛 xtu 1243 矩阵快速幂
- 快速幂/快速幂取模/矩阵求解快速幂
- 【个人模板】 快速幂取模,矩阵快速幂,快速乘
- XTOJ 1173 Five Tiger
- 快速矩阵快速幂
- 蓝桥杯 算法训练 矩阵乘方(矩阵快速幂取模)
- poj 3070 Fibonacci(矩阵快速幂取模)
- POJ - 3070 Fibonacci 矩阵快速幂取模
- hdu1005 循环节||矩阵快速幂取模
- HDU 1575 Tr A【矩阵快速幂取模】
- 快速幂取模及关于矩阵的应用
- 矩阵快速幂取模--cf678d Iterated linear function
- xtu补考题解
- Java连接数据库的两种方法
- 重绘与回流——影响浏览器加载速度
- 初碰Java垃圾回收机制
- jsp ----session
- XTOJ 1243 2016【矩阵快速幂取模】
- 突然发现的新姿势
- AdaBoost算法
- Python数据可视化:顶级绘图库plotly
- 可重入函数与不可重入函数概念以及编写规范
- Android快速开发系列 10个常用工具类
- hdoj1754-I Hate It && 1166-敌兵布阵
- Linux多线程的同步与互斥
- 串口的一些高级用法arduino