HDU 4565 So Easy!(矩阵快速幂)
来源:互联网 发布:网络直播收入排名 编辑:程序博客网 时间:2024/05/22 08:22
这里写的很详细了啊:http://blog.csdn.net/acmmmm/article/details/9722515?utm_source=tuicool
记录一下,回头复习用啊。
So Easy!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2281 Accepted Submission(s): 708
Problem Description
A sequence Sn is defined as:
Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.
You, a top coder, say: So easy!
Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.
You, a top coder, say: So easy!
Input
There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 215, (a-1)2< b < a2, 0 < b, n < 231.The input will finish with the end of file.
Output
For each the case, output an integer Sn.
Sample Input
2 3 1 20132 3 2 20132 2 1 2013
Sample Output
4144
Source
2013 ACM-ICPC长沙赛区全国邀请赛——题目重现
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-10///#define M 1000100#define LL __int64///#define LL long long///#define INF 0x7ffffff#define INF 0x3f3f3f3f#define PI 3.1415926535898#define zero(x) ((fabs(x)<eps)?0:x)///#define mod 10007const int maxn = 210;using namespace std;struct matrix{ LL f[3][3];};LL mod;matrix mul(matrix a, matrix b, int n){ matrix c; memset(c.f, 0, sizeof(c.f)); for(int k = 0;k < n; k++) { for(int i = 0; i < n;i++) { if(!a.f[i][k]) continue; for(int j = 0; j < n; j++) { if(!b.f[k][j]) continue; c.f[i][j]=(c.f[i][j]+a.f[i][k]*b.f[k][j]+mod)%mod; } } } return c;}matrix pow_mod(matrix a, LL b, int n){ matrix s; memset(s.f, 0 , sizeof(s.f)); for(int i = 0; i < n; i++) s.f[i][i] = 1LL; while(b) { if(b&1) s = mul(s, a, n); a = mul(a, a, n); b >>= 1; } return s;}int main(){ LL a, b, n; while(~scanf("%I64d %I64d %I64d %I64d",&a, &b, &n, &mod)) { if(n == 1) { printf("%I64d\n",2*a%mod); continue; } matrix c; memset(c.f, 0 , sizeof(c.f)); c.f[0][0] = 2LL*a; c.f[0][1] = b-a*a; c.f[1][0] = 1LL; matrix d = pow_mod(c, n-1, 2); printf("%I64d\n",((d.f[0][0]*2*a+d.f[0][1]*2)%mod+mod)%mod); } return 0;}
0 0
- HDU 4565 So Easy! (矩阵快速幂)
- hdu 4565 - So Easy!(矩阵快速幂)
- hdu 4565 So Easy! 矩阵快速幂
- HDU 4565 So Easy!(矩阵快速幂)
- HDU 4565 So Easy!(矩阵快速幂)
- HDU 4565So Easy! 矩阵快速幂
- hdu 4565 So Easy!(矩阵快速幂)
- HDU - 4565 So Easy! 矩阵快速幂
- HDU 4565 so easy ! 矩阵快速幂
- HDU 4565——So Easy!(矩阵快速幂乘法)
- hdu 4565 So Easy!(构造矩阵快速幂)
- 数学公式+矩阵快速幂 hdu-4565 So Easy!
- hdu 4565 So Easy!(矩阵+快速幂)
- hdu - 4565 - So Easy!(矩阵快速幂)
- HDU 4565 So Easy!(数学+矩阵快速幂)
- hdu 4565 So Easy!(推公式&矩阵快速幂)
- HDU 4565 So Easy!(矩阵快速幂)
- hdu 4565 So Easy!(矩阵快速幂)
- (1)桌面客制化之单屏幕修改以及wight修改
- malloc的内存分配之 malloc(0)的内存分配情况
- 用两个for循环实现动态创建表格和实现乘法口诀表
- 3518流媒体服务器-搭建服务器
- 爱妃阿散井安科技快乐讲啊
- HDU 4565 So Easy!(矩阵快速幂)
- Replica Island 学习笔记 04 - AndouKun
- Android解耦库EventBus的使用和源码分析
- 字节对齐
- codeforces 474C Captain Marmot dfs
- java的重写、重载、覆盖的区别
- accelerated c++答案(自写)---第三章
- C#-—体验字段
- UBuntu安裝使用PIP