Codeforces Round #118 (Div. 1) A. Plant
A. Plant
题目链接:http://codeforces.com/problemset/problem/185/A
题意:一个植物会长,一开始是一个正三角形,每过一年,一个向上的正三角形会变成三个向上的正三角形和一个向下的正三角形,一个向下的三角形可以变成三个向下的三角形和一个向上的三角形,问n年后有多少个向上的正三角形,和向下的正三角形,这是一个矩阵快速幂的裸题,很容易可以推出递推式,然后利用矩阵快速幂求就好了。
设向上三角形的数量为an,向下三角形数量为bn,则an=3*an-1+bn,bn=3*bn+an,根据这个递推式,我们可以构造矩阵求解。
3,1 * an-1 = an
1,3 bn-1 = bn
//Author: xiaowuga
#include <bits/stdc++.h>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define n 2
#define MOD 1000000007
using namespace std;
typedef long long ll;
struct Matrix{
ll mat[][];
Matrix operator * (const Matrix & m) const{
Matrix tmp;
for(int i=;i<n;i++)
for(int j=;j<n;j++){
tmp.mat[i][j]=;
for(int k=;k<n;k++){
tmp.mat[i][j]+=mat[i][k]*m.mat[k][j]%MOD;
tmp.mat[i][j]%=MOD;
}
}
return tmp;
}
};
Matrix POW(Matrix m,ll k){
Matrix ans;
memset(ans.mat,,sizeof(ans.mat));
for(int i=;i<n;i++) ans.mat[i][i]=;
while(k){
if(k&) ans=ans*m;
k/=;
m=m*m;
}
return ans;
}
int main() {
ios::sync_with_stdio(false);cin.tie();
ll T;
cin>>T;
Matrix m;
m.mat[][]=m.mat[][]=;
m.mat[][]=m.mat[][]=;
Matrix ans;
ans=POW(m,T);
cout<<ans.mat[][]%MOD<<endl;
return ;
}
Codeforces Round #118 (Div. 1) A. Plant的更多相关文章
- Codeforces Round #118 (Div. 2)
A. Comparing Strings 判断不同的位置个数以及交换后是否相等. B. Growing Mushrooms 模拟. C. Plant 矩阵+快速幂 D. Mushroom Scient ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- 关于.net 2.0 remoting 中 TCP Channel 用户认证探讨(一)
http://www.cnblogs.com/scucj/archive/2007/05/09/740808.html
- 使用 firewalld 构建 Linux 动态防火墙
firewalld 是新一 Linux 代防火墙工具,它提供了支持网络 / 防火墙区域 (zone) 定义网络链接以及接口安全等级的动态防火墙管理工具.它也支持允许服务或者应用程序直接添加防火墙规则的 ...
- Torch实现ReQU,和梯度验证
重写函数 我们使用torch实现我们自己的ReQU模块.在实现一个新的layer之前,我们必须了解,我们并不是重写forward和backward方法,而是重写里面调用的其它方法. 1)又一次upda ...
- 计算机图形学(一) 视频显示设备_1_CRT原理
第 1 章 图形系统概述 如今.计算机图形学的作用与应用已经得到了广泛承认.大量的图形硬件和软件系统已经应用 到了差点儿全部的领域.通用计算机甚至很多手持计算器也已经普遍具备 二维及三维 ...
- VMware12激活码,win10激活码
VMware Workstation 12序列号: 5A02H-AU243-TZJ49-GTC7K-3C61N win10激活码:这里在网上搜集到很多激活码,可能有的不能用. WRUF7-AFI0 ...
- PHP——分页显示的完善(加查询,用类简化sql语句)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- codeforces 429 On the Bench dp+排列组合 限制相邻元素,求合法序列数。
限制相邻元素,求合法序列数. /** 题目:On the Bench 链接:http://codeforces.com/problemset/problem/840/C 题意:求相邻的元素相乘不为平方 ...
- C++ 匿名对象产生场景
//匿名对象产生的三种场景 #include<iostream> using namespace std; class Point{ public: Point(int a,int b){ ...
- Ubuntu libpng png++安装
http://blog.csdn.net/xiaozhun07/article/details/49865785 png使用过程问题小结: (1) libpng “png_set_longjmp_fn ...
- Java Web开发SpringMVC和MyBatis框架开发环境搭建和简单有用
1.下载SpringMVC框架架包,下载地址: 点击下载 点击打开地址如图所看到的.点击下载就可以 然后把相关的jar拷贝到lib下导入 2.MyBatis(3.4.2)下载 X-Amz-Algori ...