当前位置:网站首页>【暑期每日一题】洛谷 P1255 数楼梯
【暑期每日一题】洛谷 P1255 数楼梯
2022-08-02 06:07:00 【AC_Dragon】
题目链接:P1255 数楼梯 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
楼梯有 N 阶,上楼可以一步上一阶,也可以一步上二阶。
编一个程序,计算共有多少种不同的走法。
输入格式
一个数字,楼梯数。
输出格式
输出走的方式总数。
样例 #1
样例输入 #1
4样例输出 #1
5提示
- 对于 60% 的数据,N <= 50;
- 对于 100% 的数据,1 <= N <= 5000。
AC code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
string f(string a,string b)
{
if(a=="0" && b=="0")
{
return "0";
}
int t1=a.size();
int t2=b.size();
int n=abs(t1-t2);
for(int i=0;i<n;i++)
{
if(t1>t2)
b="0"+b;
else
a="0"+a;
}
string s; // 和
int c=0; // 进位
int d=0; // 低位
int len=a.size()-1;
for(int i=len;i>=0;i--)
{
d=(a[i]-'0'+b[i]-'0')%10+c;
if(d==10)
{
c=1;
s="0"+s;
continue;
}
s=to_string(d)+s;
c=(a[i]-'0'+b[i]-'0')/10;
if(c==1 && i==0)
s="1"+s;
}
if(s[0]=='0')
s="1"+s;
return s;
}
int main()
{
vector<string> a(1);
a.push_back("1");
a.push_back("2");
for(int i=3;i<=5000;i++)
{
string t=f(a[i-2],a[i-1]);
a.push_back(t);
}
int n;
cin>>n;
cout<<a[n];
return 0;
}边栏推荐
- MySQL Advanced - MVCC (ultra-detailed finishing)
- Connection reset by peer problem analysis
- Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题
- abaqus如何快速导入其他cae文件的assembly?
- 看图就懂|衡量业务增长健康的销售指标如何选择
- mysql索引失效的常见9种原因详解
- node安装及环境配置
- MySQL 23道经典面试吊打面试官
- Leading the demand and justifying the HR value - the successful launch of the "Human Resource Leading Model HRLM"
- 能与观众实时互动的Claper
猜你喜欢

APP专项测试:流量测试

MySQL union query (multi-table query)

About the local server problem after ue4.27 pixel streaming package

Pagoda+FastAdmin 404 Not Found

MySQL classic 50 practice questions and the most detailed analysis of the whole network

有点奇怪!访问目的网址,主机能容器却不行

Clapper that can interact with the audience in real time

MySQL - 多表查询与案例详解

Xgboost报错 ValueError: Invalid shape: (1650, 2) for label

武汉高性能计算大会2022举办,高性能计算生态发展再添新动力
随机推荐
Nodejs安装教程
C# Coding Conventions Handbook
CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
[Dataset][VOC] Eyewear dataset 6000 in VOC format
有人开源全凭“为爱发电”,有人却用开源“搞到了钱”
Connection reset by peer problem analysis
mysql索引失效的常见9种原因详解
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
MySQL database video tutorial from beginner to proficient
HCIP day one
Specified URL is not reachable,caused by :‘Read timed out
看图就懂|衡量业务增长健康的销售指标如何选择
解决:- SPY: No data found for this date range, symbol may be delisted报错
request.getSession(),的故事
APP special test: traffic test
解决C#非静态字段、方法或属性“islandnum.Program.getIslandCount(int[][], int, int)”要求对象引用
Nacos installation detailed process
MySQL驱动jar包的下载--保姆教程
Py之mlxtend:mlxtend库的简介、安装、使用方法之详细攻略
[数据集][VOC]男女数据集voc格式6188张