2016"百度之星" - 资格赛(Astar Round1)Problem B
来源:互联网 发布:电路图设计软件下载 编辑:程序博客网 时间:2024/05/17 21:06
B
题解
推下前几个,发现这是一个斐波那契数列。
高精度。
#include <iostream>#include <cstdio>#include <string>#include <algorithm>using namespace std;typedef unsigned long long ull;const int maxn = 210;string dp[maxn];string add(string &a, string& b){ string ans; string aa(a.rbegin(), a.rend()); string bb(b.rbegin(), b.rend()); int i = 0; int carry = 0, sum = 0; while(i < aa.length() && i < bb.length()){ sum = (aa[i] - '0') + (bb[i] - '0') + carry; carry = sum / 10; ans.push_back(sum % 10 + '0'); ++i; } while(i < aa.length()){ sum = (aa[i] - '0') + carry; carry = sum / 10; ans.push_back(sum % 10 + '0'); ++i; } while(i < bb.length()){ sum = (bb[i] - '0') + carry; carry = sum / 10; ans.push_back(sum % 10 + '0'); ++i; } if(carry){ ans.push_back(carry + '0'); } return string(ans.rbegin(), ans.rend());}int main(){ dp[1] = "1", dp[2] = "2"; for(int i = 3; i <= 200; ++i){ dp[i] = add(dp[i - 1], dp[i - 2]); } int n; while(cin >> n){ cout << dp[n] << endl; } return 0;}
0 0
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- Problem B 2016"百度之星" - 资格赛(Astar Round1)
- 2016"百度之星" - 资格赛(Astar Round1) Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1) Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem A
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1)Problem D
- Problem D 2016"百度之星" - 资格赛(Astar Round1)
- 2016"百度之星" - 资格赛(Astar Round1)Problem B(斐波那契数列)
- 2016"百度之星" - 资格赛(Astar Round1)Problem B (大整数+组合数)
- 2016"百度之星" - 资格赛(Astar Round1)(Problem-B)(Java 水)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A B C D--java代码
- 2016"百度之星" - 资格赛(Astar Round1)Problem B(大数加法)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A(快速幂+逆元)
- 2016"百度之星" - 资格赛(Astar Round1)Problem D(排序+map)
- mac-pro连接vpn后无法上网但是可以登录qq故障解决备忘
- 2016"百度之星" - 资格赛(Astar Round1)Problem A
- iOS中书写代码规范
- (二) 桌面应用程序的用户界面
- Android 判断字符串是数字、中文还是字母的方法
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- church计数
- cocos2d热更新代码分析
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- ubuntu14.10修改源
- 最近笔记2
- web项目启动提示class path resource does not exist(eclipse构建classes)
- oracle 从os文件读blob,从表中读blob写到os文件中
- 服务器监控(包括性能指标与web应用程序)