Codeforces Round #118 (Div. 2) C. Plant (找规律)

告别信号毛刺!手把手教你用ADS和IBIS-AMI模型搞定PCIe Gen3眼图仿真 本文详细介绍了如何使用Keysight ADS和IBIS-AMI模型进行PCIe Gen3眼图仿真,解决高速信号传输中的信号质量问题。从仿真环境搭建、S参数预处理到眼图优化与故障排除,提供了一套完整的工程实践指南,帮助工程师提升PCIe Gen3接口的信号完整性。 阅读详情

题目链接:点击打开链接

题意:问你第n个大三角形中有几个小三角形是朝上的。


思路:每个朝上的小三角形下一年会变成三个朝上一个朝下,每个向下的小三角下年会变成三个朝下一个朝上。


我们可以设第i年朝上的是ai个朝下的是bi个,因此可以得到递推式:ai = 3*ai-1 + bi-1, 

bi = 3*b*-1 + ai-1, 可以看到这个式子很像,两者做差得到ai-bi = 2*(ai-1 - bi-1),可得到

第i年两者之差的公式,又可知每年有4^i个三角,即ai + bi = 4^i, ai - bi = 2^n 两者作和

除2即为答案,快速幂即可解决。



代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n;

ll p(ll a, ll k)
{
    a %= mod;
    ll ans = 1;
    while(k)
    {
        if(k&1) ans = ans*a%mod;
        a = a*a%mod;
        k /= 2;
    }
    return ans;
}

int main(void)
{
    while(cin >> n)
    {
        if(!n) puts("1");
        else printf("%I64d\n", (p(2, n-1)+p(2, 2*n-1))%mod);
    }
    return 0;
}



C. Plant
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.

Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

Input

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64dspecifier.

Output

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

Examples
input
1
output
3
input
2
output
10
Note

The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.





机器人中的数值优化(十五)——PHR增广拉格朗日乘子法 本系列文章主要是我在学习《数值优化》过程中的一些笔记和相关思考,主要的学习资料是深蓝学院的课程《机器人中的数值优化》和高立编著的《数值最优化方法》等,本系列文章篇数较多,不定期更新,上半部分介绍无约束优化,下半部分介绍带约束的优化,中间会穿插一些路径规划方面的应用实例 阅读详情

相关推荐

1.3、云计算HCIP融合存储产品及部署

目标:描述Oceanstor V3系列存储产品系统组成及产品定位 描述Oceanstor V3硬件结构及软件架构 掌握存储系统与主机系统之间的连接 一、存储型号 低端型存储:Oceanstor 2200 2600 2800 V3/V5 终端型存储:Oceanstor 5300 5500 5600 5800 6800 V3/V5 高端型存储:Oceanstor 18000 二、Oceanstor V3系列存储系统定位 OceanStor V3系列存储系统是华为根据存储产品应用现状和存储

weixin_43666279的博客 1659

Plant(矩阵快速幂)

A. Plant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dwarfs have planted a very interesting plant, which is a ...

Simone chou... 202

GNSS数据处理新手避坑:手把手教你用GAMP_GOOD下载IGS/MGEX数据(附.cfg文件详解)

本文详细介绍了如何使用GAMP_GOOD进行GNSS数据处理,从基础配置到高级参数调优,帮助新手避开常见错误。内容包括软件安装、配置文件详解、数据源选择、测站文件配置以及性能优化技巧,特别适合GNSS数据处理初学者快速上手。

weixin_30338481的博客 392

CodeForces - 185A ( Plant)

A. Plant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dwarfs have planted a very interesting plant, whic

passer__的博客 361

从零到一:YOLOv8在边缘设备上的轻量化部署实战

本文详细介绍了YOLOv8在边缘设备上的轻量化部署实战,涵盖模型优化、TensorRT加速、剪枝与知识蒸馏等关键技术。通过工业质检和智能门禁项目案例,展示了如何将YOLOv8高效部署到树莓派、Jetson Nano等资源受限设备,显著提升推理速度和降低内存占用。文章还提供了动态分辨率调整、多模型级联部署等实用技巧,助力开发者实现边缘AI应用的高效落地。

weixin_29040367的博客 383

Unity开发微信小游戏,使用Addressables管理游戏资源(本地进行远程测试)

快速构建Unity微信小游戏 使用Addressables管理游戏资源 使用小皮助手在本地进行远程资源加载测试

the_vnas的博客 6398

Plant (矩阵快速幂)

题目链接:http://codeforces.com/problemset/problem/185/A 题目: Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a...

di6499的博客 636

基于EKF的UWB-IMU融合定位系统在农业机器人中的抗干扰优化与Matlab仿真

本文探讨了基于扩展卡尔曼滤波(EKF)的UWB-IMU传感器融合定位系统在农业机器人中的应用。通过Matlab仿真验证,该系统有效解决了农业环境中UWB信号遮挡和IMU累积误差问题,实现了厘米级高精度定位,显著提升了机器人在复杂场景下的抗干扰能力和导航可靠性。

numpy6sculptor的博客 629

简单数学训练—C

Description Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into

GrEedWish_X的专栏 695

多模态对齐方案

本文中我们介绍了 13 中常见的大型多模态模型(Large Multimodal Models, LMM),包括 BLIP-2,LLaVA、MiniGPT、Qwen-VL 以及 Ferret 等。最全 LMM 模型结构(13种)综述。单层linear投影、两层mlp。

liguandong 2093

2023推免(夏令营+套实验室)面试总结(博文附问题汇总和参考答案)

2023推免(夏令营+套实验室)面试总结(博文附问题汇总和参考答案)

m0_51339444的博客 1818

[PlantSimulation]PS与Excel(实例一)

如题。端午节快乐!

Ronnie的博客 4278

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #118 (Div. 2) C. Plant

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle p...

lee371042的博客 246

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces Round #118 (Div. 2)-C-Plant(构造矩阵)

A. Plant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dwarfs have planted a very interesting plant, whic

信仰.的博客 599

CodeForces 185A. Plant(矩阵快速幂)

CodeForces 185A. Plant(矩阵快速幂)

2147

CodeForces - 185A Plant

Description Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into

Run 6368

【CF185A】Plant

题目描述 Dwarfs have planted a very interesting plant, which is a triangle directed “upwards”. This plant has an amusing feature. After one year a triangle plant directed “upwards” divides into four tria...

dingxingdi的博客 593

codeforces 118A String Task(字符串水题)

A. String Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya started to attend programming lessons. On the fi

1614

CodeForces-185A(矩阵快速幂)

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle p

Swust_ZzK的博客 515

CodeForces 185A Plant(公式推导+快速幂)

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will p

HJY 399

codeforces 185A Plant

点击打开cf 185A 思路: 递推+矩阵快速幂 分析: 1 题目要求找到在n年后向上三角形的个数 2 写出前面的几个数F(0) = 1 , F(1) = 3 , F(2) = 10 , F(3) = 36 , F(4) = 136 通过前面几项我们可以找到通项公式F[n] = 4*F[n-1]-2^(n-1) 那么我们通过够找矩阵 | 4 -1 | * | F(n-1) | ...

我是传奇 235

Plant

忽然觉得数论的题目模板套的好爽 本来想着用上一题的构造序列的感觉做,莫名翻车,发现没有必要,他只是给你这样好理解的而已 {3   1}*{f(n-1)上}={f(n)上}  1    3   f(n-1)下     f(n)下 其实就可以直接用构造出的二维数组的n次方解题 再一次在while(scanf)跌倒 F - Plant Time Limit:2000MS

yinghui_yht的博客 466

Codeforces Round #118 (Div. 1) A. Plant 矩阵快速幂(矩阵构造) 模板

A. Plant time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dwarfs have planted a very interesting plant, which is a triangle direct...

人生如戏 217

CodeForces - 118A 字符串处理入门 难度:C++入门 复杂度:一般 翻译难度:有点难...

Petya开始上编程课了。第一堂课他的任务是写一个简单的程序。 这个程序应该做到以下事情:给定一个由大小写字母组成的字符串,使它: 1.删除所有元音(包括大小写) 2.在每个辅音前插入一个字符"." 3.将所有大写辅音字母改为小写 (此处规定,)元音字母是A,O,Y,E,U,I,...

chishi6516的博客 453

CodeForces-118A

问题链接:CodeForces-118A 问题简述:将输入的字符串中含有的元音字母删去,辅音字母改为小写,并在前面加一个“.”。 问题分析:该题考察 if、for语句 ascll值以及对题目的理解能力。 程序说明:#include using namespace std; int main() { int i; char x[101]; cin &gt;&gt; x; if (x == '...

qq_43964924的博客 269

codeforces-346A-Alice and Bob【数论】

codeforces-346A-Alice and Bob【数论】

Linoy 1793

Codeforces Round #118 (Div. 1) A. Plant(快速幂)

题目 Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four tr

ff137774288的博客 412
上一篇: Codeforces Round #304 (Div. 2) D. Soldier and Number Game(筛选素因子,前缀和)
下一篇: lightoj 1036 A Refining Company(dp)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值