Sicily 1029. Rabbit
来源:互联网 发布:男士护肤面膜 知乎 编辑:程序博客网 时间:2024/06/03 16:47
题目要不是提醒了一下m = 2的时候发是fibonacci sequence以我的水平估计是看不出来数据模型~~~
所以还是愚蠢地用了列举方法,分别了m = 1, m = 2, m = 3然后d = 10的情况去观察规律。
最后还有个高精度加法,第一次接触,有点头疼,好多细节不完善,所以还是参考了下前辈的思路: 点击打开链接
看完再自己动手写了一遍
好慢 不知道主要是不是cin cout的原因,好想知道前面0.00sec的是怎么写的,期待告知!
// Problem#: 1029// Author: Reid Chan#include <iostream>#include <string>#include <cstring>using namespace std;void integer_2_string(int num, string &str){ str = ""; char ch; while (num != 0) { ch = (num % 10) + '0'; str = ch + str; num /= 10; }}string high_accuracy_addition(string left, string right){ int len_l = left.length(); int len_r = right.length(); while (len_l < len_r) { left = '0' + left; len_l++; } while (len_r < len_l) { right = '0' + right; len_r++; } left = '0' + left; right = '0' + right; int carry = 0; string result = ""; char re; int trans; for (int i = left.length() - 1; i >= 0; --i) { trans = (left[i] - '0' + right[i] - '0') + carry; if (trans > 9) { re = (trans - 10) + '0'; carry = 1; } else { re = trans + '0'; carry = 0; } result = re + result; } if (result[0] == '0') { result = result.substr(1, result.length() - 1); } return result;}int main() { int m, d; string str[101]; while (cin >> m >> d && (m != 0 && d != 0)) { int pre = 0, now = 0; for (int i = 0; i < m; ++i) { now = pre + 1; integer_2_string(now, str[i]); pre = now; } if (d < m) { cout << str[d] << endl; } else { for (int i = m; i <= d; ++i) { str[i] = high_accuracy_addition(str[i - 1], str[i - m]); } cout << str[d] << endl; } } return 0;}
0 0
- Sicily 1029. Rabbit
- [sicily online]1029. Rabbit
- Sicily 1029. Rabbit
- Sicily 1029. Rabbit
- sicily 1029.Rabbit
- Sicily 1029. Rabbit
- [sicily]1029. Rabbit
- sicily 1029. Rabbit
- Sicily 1029. Rabbit --by rupeng
- Sicily.1029. Rabbit(递推)
- Sicily 1029. Rabbit【高精度加法】
- Sicily 1029 Rabbit
- sicily 1029 Rabbit
- Sicily 1029 Rabbit
- sicily 1029. Rabbit | 高精度加法+递推(类斐波那契推导)
- 1029. Rabbit
- 1029. Rabbit
- 1029. Rabbit
- Arcgis for Js实现graphiclayer的空间查询
- POJ 2425
- 找二叉树中两个节点的最近的公共父节点(三种情景)
- 推荐!国外程序员整理的 C++ 资源大全(原文http://fffaraz.github.io/awesome-cpp/#standard-libraries)
- Winpcap网络编程十之Winpcap实战,两台主机通过中间主机通信
- Sicily 1029. Rabbit
- Power Network (poj 1459 网络流)
- css盒子模型及实例
- Linux笔记
- socket 使用
- 博弈
- 第九周项目三输出星号图(f)
- poj1256
- python判断文件和文件夹是否存在、创建文件夹