So happy!(get 矩阵快速幂)ICPC :E HDU 6198
来源:互联网 发布:盐城都玩网络 编辑:程序博客网 时间:2024/06/02 07:19
- number number number
Time Limit: 2000/1000 MS (Java/Others) Memory
Limit: 32768/32768 K (Java/Others) Total Submission(s): 637Accepted Submission(s): 407
Problem Description We define a sequence F:⋅ F0=0,F1=1; ⋅ Fn=Fn−1+Fn−2 (n≥2).
Give you an integer k, if a positive number n can be expressed by
n=Fa1+Fa2+…+Fak where 0≤a1≤a2≤⋯≤ak, this positive number is
mjf−good. Otherwise, this positive number is mjf−bad. Now, give you
an integer k, you task is to find the minimal positive mjf−bad
number. The answer may be too large. Please print the answer moduloInput There are about 500 test cases, end up with EOF. Each test case
includes an integer k which is described above. (1≤k≤109)Output For each case, output the minimal mjf−bad number mod
Sample Input
1
Sample Output
4
Source 2017 ACM/ICPC Asia Regional Shenyang Online前提:矩阵快速幂+斐波那契数列推荐题目(poj3070(斐波那契的矩阵表示))
思路:
* 题目要求找bad number,枚举钱四项分别是 4,12,33,88,斐波那契数列为0 , 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89*
对应的下标分别是0,1,2,3,4,5,6,7,8,9,10,11
第一个bad number: 4=f4+f3-1;
第二个bad number :12=f5+f6-1;
第三个bad number: 33 =f7+f8-1;
* 因而推导出一下公式: a(n)=f(2*n+2)+f(2*n+1)-1*
代码如下:
#include <bits/stdc++.h>using namespace std;const int mod =998244353;struct matrix{ long long int a[2][2];};matrix multply(matrix x,matrix y){ matrix result ; memset(result.a,0,sizeof(result.a)); int i,j,k; for (i=0;i<2;i++) for (j=0;j<2;j++) for (k=0;k<2;k++) { result.a[i][j]+=x.a[i][k]*y.a[k][j]; if(result.a[i][j]>=mod) result.a[i][j]%=mod; } return result;}matrix pow_mod (matrix a,int n){ matrix result; memset(result.a,0,sizeof(result.a)); for (int i=0;i<2;i++) result.a[i][i]=1; while (n) { if(n&1) result=multply(result,a); a=multply(a,a); n>>=1; } return result ;}int main (){ long long int n; while (cin>>n) { n=2*n+1; long long int ans; matrix a; a.a[0][0]=a.a[0][1]=a.a[1][0]=1; a.a[1][1]=0; a=pow_mod(a,n); ans =a.a[0][0]+a.a[0][1]-1;// int i,j;// for (i=0;i<2;i++)// for (j=0;j<2;j++)// if(!j)// cout<<a.a[i][j]<<" ";// else// cout <<a.a[i][j]<<endl; if(ans>=mod) ans%=mod; cout<<ans<<endl; } return 0;}
- So happy!(get 矩阵快速幂)ICPC :E HDU 6198
- HDU 4565 So Easy!(思想+矩阵快速幂)——2013 ACM-ICPC长沙赛区全国邀请赛
- HDU 6030 Happy Necklace (递推+矩阵快速幂)
- hdu 6030 Happy Necklace (递推,矩阵快速幂)
- HDU 6030 Happy Necklace【矩阵快速幂】
- HDU 6030 Happy Necklace【矩阵快速幂】
- hnu13150(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 4565So Easy!(巧妙的矩阵快速幂)
- HDU 4565 So Easy! (矩阵快速幂)
- 数据库连接池浅析
- 开机广播的简单实现
- SSH整合的时候启动tomcat报错
- 忘记密码前端
- activiti和业务集成:使用aop
- So happy!(get 矩阵快速幂)ICPC :E HDU 6198
- 何去何从,困惑!
- Servlet.service() for servlet [springMVC] in context with path [] threw exception [Could not get Req
- 在实际使用它的过程中不需要再次使用 ‘
- 天天学Linux命令22--find命令之xargs
- 静态代码块,构造代码块与构造函数
- python中matplotlib画图中文不能显示
- 静态什么时候用?
- vim 插件安装