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后和给 ...
随机推荐
- [POJ 1236][IOI 1996]Network of Schools
Description A number of schools are connected to a computer network. Agreements have been developed ...
- Windows Phone 性能优化(一)
在实际的项目开发过程中,应用的性能优化是一个永恒的话题,也是开发者群里最常讨论的话题之一,我在之 前的公司做 wp项目时,也遇到过性能的瓶颈.当页面中加载的内容越来越多时,内存涨幅非常明显(特别是 一 ...
- 整合quickx到普通cocos2dx
quickx是对cocos2dx的lua扩展,它做了一些C++的扩展,同时还在lua做了一些封装, 让用lua开发cocos2dx更快,中文站http://quick.cocoachina.com/. ...
- signal基础
signal man 7 signal 1.kill -l 显示所有信号 kill -signal PID killall -signal name 2.产生信号 ctrl+c => SIGIN ...
- 绑定内网和安全redis和mongo以及MQ
redis允许局域网访问其实很简单.网上一堆都不怎么靠谱. 特此记录一下. 可参考此篇 假设A B 两台机器 在B(ip:192.168.1.99)机器上修改redis配置文件 bind 192.16 ...
- php扩展安装
[root@129-2-10-2 src]# cat kuozhan.sh #!/bin/bash###install redis extend #########cd /usr/local/srct ...
- 关于Unity中的transform组件(一)
一.transform组件用途 1.维护场景树 2.对3D物体的平移,缩放,旋转 二.场景树定义 在Hierarchy视图中显示的: 一个game_scene场景,下面有Main Camera节点,D ...
- 那么类 Man 可以从类 Human 派生,类 Boy 可以从类 Man 派生
若在逻辑上 B 是 A 的“一种”(a kind of ),则允许 B 继承 A 的功 能和属性. 例如男人(Man)是人(Human)的一种,男孩(Boy)是男人的一种. 那么类 Man 可以从类 ...
- error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
运行php-5.3.10 --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --e ...
- python3----scrapy(笔记)
import scrapy import sys # import io # sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb ...