9-10 November
cout 和 printf 在 C++ 中的实现:四舍六入五随缘。比如 printf("%.0lf\n", x=1.5)
=> 1。
标准做法:printf("%d\n", (int)(x+0.5))
。
矩阵乘法
由 \(a_n=2a_{n-3}+a_{n-1}\) 得矩阵转移方程:
\]
这里采用 []
表示 \(1\times 3\) 矩阵,()
表示 \(3\times 3\) 矩阵。
ll p[5][5], b[5][5], d[5][5], t[5][5];
memset(p, 0, sizeof p), memset(b, 0, sizeof b), memset(d, 0, sizeof d);
for (int i=1; i<=3; i++) b[i][i]=1ll; // unit matrix
p[1][1]=1ll, p[1][2]=1ll, p[1][3]=0ll;
p[2][1]=0ll, p[2][2]=0ll, p[2][3]=1ll;
p[3][1]=2ll, p[3][2]=0ll, p[3][3]=0ll; // transition matrix
d[1][1]=6ll, d[1][2]=1ll, d[1][3]=3ll; // initial matrix, a_3, a_2, a_1
// n<=3 特判
if (n<=3) {printf("%d\n", d[1][4-n]); return 0; }
// 矩阵快速幂
int K=n-3;
while (K>0){
if (K&1) {
// (b) *= (p)
memset(t, 0, sizeof t);
for (int i=1; i<=3; i++)
for (int j=1; j<=3; j++)
for (int k=1; k<=3; k++)
t[i][j]=(t[i][j]+b[i][k]*p[k][j]) % mod;
memcpy(b, t, sizeof b);
}
// (p) = (p)^2
memset(t, 0, sizeof t);
for (int i=1; i<=3; i++)
for (int j=1; j<=3; j++)
for (int k=1; k<=3; k++)
t[i][j]=(t[i][j]+p[i][k]*p[k][j]) % mod;
memcpy(p, t, sizeof p);
K>>=1;
}
// [t] = [d] * (b)
memset(t, 0, sizeof t);
for (int i=1; i<=3; i++)
for (int j=1; j<=3; j++)
t[1][i]=(t[1][i]+d[1][j]*b[j][i]) % mod;
printf("%lld\n", t[1][1]);
9-10 November的更多相关文章
- 各个版本 Windows 10 系统中自带的 .NET Framework 版本
原文各个版本 Windows 10 系统中自带的 .NET Framework 版本 Windows 名称 Windows 版本 自带的 .NET Framework 版本 Windows 10 Oc ...
- centos各版本信息
CentOS version Architectures RHEL base Kernel CentOS release date RHEL release date Delay (days) 2.1 ...
- 获取机器安装.NET版本的几种方式
当调查应用程序问题时,通常需要先确认目标机器所安装的 .NET Framework 的版本.可以通过如下方式来确认版本号: 通过控制面板安装程序查询 通过查询注册表获取版本信息 通过查看安装目录获取版 ...
- SNMP进阶
管理信息库:MIB 我们要扩展mib首先必须清楚mib是如何定义的,用的什么语言,有哪些约定,遵循哪些规则等等.这些基本东西掌握过后,我们就可以很轻松的来写自己的mib文件了. 所谓管理信息库,或者M ...
- Windows、VS 与 .net
原文地址:https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx .NET Framework version CLR ver ...
- 检测电脑安装的net framework版本
https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx To find .NET Framework versions by ...
- News: Visual Studio Code support debugging Linux Apps
http://arstechnica.com/information-technology/2015/11/visual-studio-now-supports-debugging-linux-app ...
- PostgreSQL中initdb做了什么
在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...
- ### Paper about Event Detection
Paper about Event Detection. #@author: gr #@date: 2014-03-15 #@email: forgerui@gmail.com 看一些相关的论文. 1 ...
- authbind start tomcat services as user with less that 1024 ports. linux常规用户使用tomcat的80端口
Start tomcat services using authbind this will allow user to start ports less than 1024 we do not ne ...
随机推荐
- 关于SQL连接语句中的Integrated Security=SSPI/ture/false
解决方法:即:Security Support Provider Interface设置Integrated Security为 True 的时候,连接语句前面的 UserID, PW 是不起作用的, ...
- 根据select的option文本选中对应的选项
function selectByOptionTxt(obj,txt){ var optionArr = $(obj).find("option"); for(var i=0;i& ...
- 第十四周总结&实验报告八
实验八 实现一个简单的记事本操作,有菜单项的 import java.awt.event.ActionEvent; import java.awt.event.ActionListener; impo ...
- springboot项目中使用maven resources
maven resource 组件可以把pom的变量替换到相关的resouces目录中的资源文件变量 示例项目:内容中心 (文章管理) 生成jar包,生成docker ,生成k8s文件 1.项目结构 ...
- Hive-多分隔符
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.MultiDelimitSerDe' WITH SERDEPROPERTIES (&qu ...
- 【监控笔记】【1.4】Pssdiag和Sqldiag管理器
--没有实操过,有点复杂,先写上以后有用到再深入研究 统计与诊断数据是任何 SQL故障修复工作的关键所在. 如果没有掌握这些数据,就无法确定数据性能问题的根源.数据表的瓶颈可能并不是由索引问题造成的: ...
- Eclipse使用jdbc连接MySql数据库报:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
在使用eclipse连接mysql数据库时报异常: java.sql.SQLException: Access denied for user 'root'@'localhost' (using pa ...
- 【狗屁不通文章生成器】代码分析 (javaScript)
这几天在论坛上看到了一个很有意思的项目,一个生成"狗屁不通"的文章的程序.经过本人确定其的确是"狗屁不通"后,随后又好奇其实现,于是在其[GitHub]项目里( ...
- numpy库中数组的数据类型
numpy库中数组的数据类型 dtype是一个特殊的对象,它含有ndarray将一块内存解释为特殊数据类型所需要的信息 指定数据类型创建数组 >>> import numpy as ...
- Lock和synchronized的区别和使用(转发)
今天看了并发实践这本书的ReentantLock这章,感觉对ReentantLock还是不够熟悉,有许多疑问,所有在网上找了很多文章看了一下,总体说的不够详细,重点和焦点问题没有谈到,但这篇文章相当不 ...