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后和给 ...
随机推荐
- angular学习疑问总结
服务里返回的数据是不是只能传给控制器,而不能传给指令呢?如果是的话那么指令只能通过配置scope属性来访问控制器里的数据
- cocos2d-x的win32编译环境
1> 检查或配置VS 1.1>头文件 [c/c++]->附加包含目录 1.2>依赖库 [链接器]->[输入]->[附加依赖项] 2> 可能出现 ...
- javaweb reponse 写出文件
Map map = getSearchValue(); File excelFile = orderService.getexportexcel(id,map); InputStream is = n ...
- Cookie、Session详解
讲解的很全面 https://www.cnblogs.com/andy-zhou/p/5360107.html
- 跟着百度学PHP[9]-session与cookie的异同
COOKIE cookie是将数据存储在客户端中,以此建立客户端与服务器之间的联系,但是cookie任然有一些局限性: 1.cookie相对不是很安全,容易被盗用导致cookie欺骗. 2.单个的co ...
- OpenCV使用标定图
本文由 @lonelyrains 出品,转载请注明出处. 文章链接: http://blog.csdn.net/lonelyrains/article/details/46915705 上一步生成标 ...
- [shell]C语言调用shell脚本接口
Use popen if you want to run a shell command and want the parent process to be able to talk to the c ...
- Insubstantial 6.2 Release
http://shemnon.com/speling/2011/04/insubstantial-62-release.html
- java 包 和 物理目录 解惑
今天做 JUnit 实验, 发现在物理实际不同的目录(src, testsrc)下可以使用相同的包名, 并且在这两个目录下, 都有个子目录 coolUnit (这个子目录是配合 package 使用的 ...
- 页面置换算 - FIFO、LFU、LRU
缓存算法(页面置换算法)-FIFO.LFU.LRU 在前一篇文章中通过leetcode的一道题目了解了LRU算法的具体设计思路,下面继续来探讨一下另外两种常见的Cache算法:FIFO.LFU 1 ...