UVA 10334 - Ray Through Glasses(高精度斐波那契)
来源:互联网 发布:鼠标指针美化软件 编辑:程序博客网 时间:2024/04/30 17:43
Ray Through Glasses
Suppose we put two panes of glass back-to-back. How many ways are there for light rays to pass through or be reflected after changing direction n times ? Following figure shows the situations when the value of nis 0, 1 and 2.
Input
It is a set of lines with an integer n where 0 <= n <= 1000 in each of them.
Output
For every one of these integers a line containing as described above.
Sample Input
012
Sample Output
123题意:斐波那契,前1000项。
思路:用高精度去写
代码:
#include <stdio.h>#include <string.h>int n;int f[1005][35];void solve() {memset(f, 0, sizeof(f));f[0][0] = 1; f[1][0] = 2;for (int i = 2; i <= 1000; i ++) {for (int j = 0; j < 35; j ++) {f[i][j] += f[i - 1][j] + f[i - 2][j];f[i][j + 1] += f[i][j] / 100000000;f[i][j] %= 100000000;}}}void print(int n) {int i, j;for (i = 34; i >= 0; i --) {if (f[n][i] != 0)break;}printf("%d", f[n][i]);for (j = i - 1; j >= 0; j --)printf("%08d", f[n][j]);printf("\n");}int main() {solve();while (~scanf("%d", &n)) {print(n);}return 0;}
- UVa 10334 Ray Through Glasses (斐波那契&高精度)
- UVA 10334 - Ray Through Glasses(高精度斐波那契)
- uva 10334 - Ray Through Glasses(斐波那契数)
- UVa 10334 - Ray Through Glasses
- UVa 10334 - Ray Through Glasses
- UVA - 10334 Ray Through Glasses
- UVa:10334 Ray Through Glasses
- uva 10334Ray Through Glasses
- 10334 - Ray Through Glasses
- UVa10334 - Ray Through Glasses
- Ray Through Glasses
- UVA10334 - Ray Through Glasses(Fibonacci数列)
- UVA 763 - Fibinary Numbers(高精度斐波那契)
- UVA 763 - Fibinary Numbers(高精度斐波那契 + 高精度模板)
- UVa 10183 How Many Fibs? (统计斐波那契数个数&高精度)
- (高精度运算4.7.30)UVA 10579 Fibonacci Numbers(大数+斐波那契数)
- UVA 10183How Many Fibs?(高精度 斐波那契)
- UVA - 10183 - How Many Fibs? (斐波那契 + 高精度)
- Android Service完全解析,关于服务你所需知道的一切(下)
- LeetCode题解:Remove Nth Node from End of List
- 归并排序 C++/Java 递归实现代码 -犯了菜鸟老毛病
- environments was not found on the java.library.path 如何解决
- #define用法集锦
- UVA 10334 - Ray Through Glasses(高精度斐波那契)
- v8学习---添加js全局函数
- word里 怎么样自动生成目录
- Merge Two Sorted Lists
- 如何判断对象是否数组?
- HDOJ 2059 龟兔赛跑
- OK6410挂在nfs文件系统
- Android四大基本组件介绍与生命周期
- TinyOS研究链接