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 ...
随机推荐
- HTTP 常见相应状态码及含义
1xx:信息 100 Continue 服务器仅接收到部分请求,但是一旦服务器并没有拒绝该请求,客户端应该继续发送其余的请求. 101 Switching Protocols 服务器转换协议:服务器将 ...
- [Web 前端] 034 计算属性,侦听属性
目录 0. 方便起见,定个轮廓 1. 过滤器 2. 计算属性 2.1 2.2 3. 监听属性 0. 方便起见,定个轮廓 不妨记下方的程序为 code1 <!DOCTYPE html> &l ...
- [19/06/07-星期五] CSS基础_布局&定位&背景样式
一.固定布局(不适应设备的浏览器的变化) <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- Java文件手动编译执行步骤
Java编译执行步骤: 1)将 Java 代码编写到扩展名为 .java 的文件中.2)通过 javac 命令对该 java 文件进行编译.3)通过 java 命令对生成的 class 文件进行运行. ...
- tensorflow学习笔记五----------逻辑回归
在逻辑回归中使用mnist数据集.导入相应的包以及数据集. import numpy as np import tensorflow as tf import matplotlib.pyplot as ...
- spring整合apache-shiro的简单使用
这里不对shiro进行介绍,介绍什么的没有意义 初学初用,不求甚解,简单使用 一.导入jar包(引入坐标) <!--shiro和spring整合--> <dependency> ...
- HTML-美化
1.美化文本 1.1第一部分 font-size:字体大小,常用em.px.%.rem作单位,预设值small.large.medium,可继承, font-weight:加粗字体,属性为bold,加 ...
- sass和less的对比
); < { ; { { ; } ); } ); } ); // if 条件 @dr: if(@my-option = true, { button { ...
- 利用描述符自定义property
class Lazyproperty: def __init__(self,func): #传的func函数是被描述的类中的函数属性 self.func = func def __get__(self ...
- AtCoder Beginner Contest 088 D Grid Repainting
Problem statement We have an H×W grid whose squares are painted black or white. The square at the i- ...