Mr. Frog has n sticks, whose lengths are 1,2, 3
⋯
n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks he should steal so that Mr. Frog cannot form a triangle with
any three of the remaining sticks.
any three of the remaining sticks.
For each test case, there is only one line describing the given integer n ( 1≤n≤20 ).
3 4 5 6
Case #1: 1 Case #2: 1 Case #3: 2
n | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
y | 0 | 0 | 0 | 1 | 1 | 2 | 3 | 3 | 4 | 5 | 6 | 7 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
斐波那契额数列的规律
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
......
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12 13
.......
红色的是斐波那契额数列,然后黑色的是关于斐波那契推出来的规律,很容易就辨别;
直接打表就可以了;
#include <stdio.h> int main() { int a[22] = {0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14}; int N , sum = 0 , n; scanf("%d",&N); while(N--) { scanf("%d",&n); printf("Case #%d: %d\n",++sum , a[n]); } return 0; }