24h購物| | PChome| 登入
2012-06-02 17:04:21| 人氣1,034| 回應0 | 上一篇 | 下一篇

[UVA][費式] 10334 - Ray Through Glasses

推薦 0 收藏 0 轉貼0 訂閱站台


  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 n is 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 

0
1
2

Sample Output 

1
2
3

 

#include <stdio.h>
#include <stdlib.h>
int f[1001][301] = {};
int main() {
    int i, j;
    f[0][0] = 1, f[1][0] = 2;
    for(i = 2; i <= 1000; i++) {
        for(j = 0; j < 300; j++) {
            f[i][j] = f[i-1][j] + f[i-2][j];
        }
        for(j = 0; j < 300; j++) {
            f[i][j+1] += f[i][j]/10;
            f[i][j] %= 10;
        }
    }
    while(scanf("%d", &i) == 1) {
        j = 299;
        while(f[i][j] == 0) j--;
        while(j >= 0)
            putchar(f[i][j]+'0'), j--;
        puts("");
    }
    return 0;
}

台長: Morris
人氣(1,034) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][path] 341 - Non-Stop Travel
此分類上一篇:[UVA] 10036 - Divisibility

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文