hihoCoder#1143 : 骨牌覆盖问题·一
来源:互联网 发布:喜马拉雅fm软件叫 编辑:程序博客网 时间:2024/05/10 11:53
快速幂需要注意一个地方,就是别超了数字的范围,及时longlong也很容易爆炸,及时取余才是王道
http://hihocoder.com/problemset/problem/1143
#include<iostream>using namespace std;long long di[4] ;void solve(long long a[4], long long b[4], long long *cc){long long aa[4] = {a[0],a[1],a[2],a[3]};long long bb[4] = { b[0], b[1], b[2], b[3] };cc[0] = (aa[0] * bb[0] + aa[1] * bb[2]) % 19999997;//重点啊~~~~cc[1] = (aa[0] * bb[1] + aa[1] * bb[3]) % 19999997;cc[2] = (aa[2] * bb[0] + aa[3] * bb[2]) % 19999997;cc[3] = (aa[2] * bb[1] + aa[3] * bb[3]) % 19999997;int i = 0;}void ji(long long n, long long *answer){while (n){if (n & 1){solve(answer, di, answer);}solve(di, di, di);n = n >> 1;}}int main(){long long n;while (cin >> n){di[0] = 0;di[1] = 1;di[2] = 1;di[3] = 1;long long answer[4] = { 1, 0, 0, 1 };ji(n, answer);cout << answer[3] << endl;}return 0;}
0 0
- hihoCoder #1143 : 骨牌覆盖问题·一
- hihocoder 1143 : 骨牌覆盖问题·一
- hihoCoder#1143 : 骨牌覆盖问题·一
- hihoCoder 1143 : 骨牌覆盖问题·一 矩阵快速幂
- hihoCoder #1143 : 骨牌覆盖问题·一(矩阵乘法)
- hihoCoder 骨牌覆盖问题·一 hiho一下 第四十一周
- hihoCoder 1143 : 骨牌覆盖问题·一(递推,矩阵快速幂)
- hihocoder 1151 : 骨牌覆盖问题·二
- hihocoder 1162 : 骨牌覆盖问题·三
- hihocoder骨牌覆盖问题·三
- 骨牌覆盖问题·一
- hihoCoder 1151 : 骨牌覆盖问题·二 矩阵快速幂
- hihocoder 1162 : 骨牌覆盖问题·三 矩阵快速幂
- hiho 41 骨牌覆盖问题·一
- hiho一(第四十一周)------骨牌覆盖问题·一
- hihoCoder hiho一下 第四十二周:骨牌覆盖问题·二
- hihocoder 1151 : 骨牌覆盖问题·二(找规律+矩阵快速幂)
- hihoCoder hiho一下 第四十一周:骨牌覆盖问题
- ext2文件系统源代码之Makefile
- STL中set用法详解
- 字符串小练习
- 《PHP: a fractal of bad design》笔记
- 蓝桥杯--2013--翻硬币(贪心)
- hihoCoder#1143 : 骨牌覆盖问题·一
- hdu1894 String Compare(string判断子串)
- OpenJudge百炼习题解答(C++)--题3142:球弹跳高度的计算
- jmeter入门3
- AsyncTask工作原理
- 我的Xcode插件列表
- 如何判断我的电脑是否为通过UEFI模式启动
- Struts2和Tiles集成
- delegate为什么要用weak