Sicily 1029 Rabbits
来源:互联网 发布:淘宝 黑搜与白搜 编辑:程序博客网 时间:2024/05/22 17:11
f(n)=f(n-1)+f(n-m)
高精度加法
#include <iostream>#include <string>#include <vector>using namespace std;string add(string a, string b) {// Assumption: a>bint carry=0;string::reverse_iterator aIter=a.rbegin();string::reverse_iterator bIter=b.rbegin();while(bIter!=b.rend()) {int tmp=(*aIter)-'0'+(*bIter)-'0'+carry;(*aIter)=tmp%10+'0';carry=tmp/10;aIter++;bIter++;}if (carry==1) {while (aIter!=a.rend())if ((*aIter!='9'))break;else(*aIter++)='0';if (aIter!=a.rend())(*aIter)+=1;elsea.insert(aIter.base(), '1');}return a;}int main() {int m, d;while(cin>>m>>d, m!=0) {vector<string> rabbits(m, "0");int month;rabbits[0]="2";for (month=1; (month<m) && (month<d); month++)rabbits[month]=add(rabbits[month-1], "1");for (;month<d; month++)rabbits[month%m]=add(rabbits[(month-1)%m], rabbits[(month-m)%m]);cout<<rabbits[(month-1)%m]<<"\n";}}// by wbchou// Feb 19th, 2013
- Sicily 1029 Rabbits
- sicily 1029 Rabbits
- sicily 1029
- SIcily 1029
- sicily 1029
- Running Rabbits
- HDU6227 ---Rabbits
- Sicily 1029 Rabbit
- sicily 1029 Rabbit
- Sicily 1029 Rabbit
- The quality of Rabbits
- hdu 4452 Running Rabbits
- hdu 4452 Running Rabbits
- HDU Running Rabbits(模拟)
- hdu 4452 Running Rabbits
- hdu - 4452 - Running Rabbits
- HDU4745 Two Rabbits
- HDU-4745-Two Rabbits
- Struts2.0中ActionInvocation使用
- Oracle RAC 11g 环境 启动和关闭顺序
- Apache 无法启动问题之一
- 把vim配成IDE,以及用vim阅读代码
- 转载_Windows编程革命简史
- Sicily 1029 Rabbits
- Java中的IO整理
- jdbc + CallableStatement +Incorrectly registered parameters - JDBC JAVA
- 转载_程序员技术练级攻略
- jquery版本banner的效果[面向对象]
- JavaScript语言精粹
- FTP中文件名乱码问题(转)
- 获取被加载dll路径和应用程序运行目录
- poj 1419 最大团