走楼梯
来源:互联网 发布:58网络电视直播 编辑:程序博客网 时间:2024/06/02 12:09
走楼梯
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description
小虎发现走楼梯的时候一次上一个台阶比较惬意,一次上两个台阶比较高效,一次上三个台阶就很累人。
小虎是一个即注重质量又注重高效的人,于是他就在上楼梯的时候每步就只跨上一个台阶或两个台阶,
现在小虎想知道他这样上n阶的楼梯一共有多少种走法,但是他又不想亲身经历,只好求助于会编程的你,帮他解决这个问题了。
Input
第一行是T,表示接下来有T组输入,每组输入一个N(2 <= N <= 1000)
Output
对应每组输入输出一共有多少种走法。
Example Input
310922
Example Output
895528657
#include<iostream>#include<algorithm>using namespace std;string stra(int ad,int index,string a){ a[index] = (char)(ad%10 + 48); ad = ad/10; int in = index + 1; if(in >= a.length()){ a.push_back('0'); } int n = (int)(a[index+1] - 48); ad = ad+n; if(ad> 10){ stra(ad,index+1,a); }else{ a[index+1] = (char)(ad + 48); return a; }}string stradd(string a,string b){ int lengtha = a.length(); int lengthb = b.length(); if(lengtha > lengthb){ for(int i=0; i<lengthb; i++){ int m = (int)(b[i] - 48); int n = (int)(a[i] - 48); int ad = n+m; if(ad < 10){ a[i] = (char)(ad + 48); }else{ a = stra(ad,i,a); } } return a; }else{ for(int i=0; i<lengtha; i++){ int m = (int)(a[i] - 48); int n = (int)(b[i] - 48); int ad = n+m; if(ad < 10){ b[i] = (char)(ad + 48); }else{ b = stra(ad,i,b); } } return b; }}int main(){ int t; cin>>t; while(t--){ int n; string a="1",b="2",c; cin>>n; if(n == 2){ c = "2"; }else{ for(int i=3; i<=n; i++){ c = stradd(a,b); a = b; b = c; } } reverse(c.begin(),c.end()); cout<<c<<endl; } return 0;}
阅读全文
0 0
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯
- 走楼梯问题
- 楼梯的走法
- 走楼梯问题
- SDUT2876_走楼梯(大数)
- Problem 1031 - 走楼梯
- 动态规划走楼梯
- SDUT OJ 走楼梯
- hdu 2041 走楼梯
- 动态规划-走楼梯
- 使用html+css实现简单的箭头
- 逆向汇编基础
- 第二天 我认为较为高级的命令 cut
- 第11周项目4- 利用遍历思想求解图问题(2)
- JAVA----日期处理
- 走楼梯
- Python+Opencv+Qt4编写Windows下摄像头图像采集显示程序
- 前端基础之CSS3
- HDU 6231 K-th Number 尺取法
- spring06 aop 引入
- 8皇后问题
- 机器学习(1) ---- 机器学习算法综述
- vmware克隆centOS虚拟机
- [4]_[解决]Ubuntu16.04.3 DNS解析失败