标签:
Fibonacci序列Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB
Total Submission: 34 Submission Accepted: 12DescriptionFibonacci 数列的另一种形式
F(0)=7, F(1)=11 F(n)=F(n-1)+F(n-2) (n>=2)
Input包括多行,每行有一个整数n(n<1,00,000),当n<0时表示输入结束
Output对应输入的n,若序列的第n项能被3整数,则输出Yes,否则输出No.
Sample Input
Original Transformed 0 1 2 3 4 5 -1
Sample Output
Original Transformed No No Yes No No No
递推+记忆化搜索即可
AC代码:GitHub
1 /* 2 By:OhYee 3 Github:OhYee 4 HomePage:http://www.oyohyee.com 5 Email:oyohyee@oyohyee.com 6 Blog:http://www.cnblogs.com/ohyee/ 7 8 かしこいかわいい? 9 エリーチカ! 10 要写出来Хорошо的代码哦~ 11 */ 12 13 #include <cstdio> 14 #include <algorithm> 15 #include <cstring> 16 #include <cmath> 17 #include <string> 18 #include <iostream> 19 #include <vector> 20 #include <list> 21 #include <queue> 22 #include <stack> 23 #include <map> 24 using namespace std; 25 26 //DEBUG MODE 27 #define debug 0 28 29 //循环 30 #define REP(n) for(int o=0;o<n;o++) 31 32 const int maxn = 100005; 33 int f[maxn]; 34 int F(int n) { 35 if(f[n] == -1) { 36 f[n] = F(n - 1) + F(n - 2); 37 } 38 return f[n]; 39 } 40 41 bool Do() { 42 int n; 43 if(scanf("%d",&n),n<0) 44 return false; 45 46 //printf("%d %d ",n,F(n)); 47 printf((F(n) % 3) == 0 ? "Yes\n" : "No\n"); 48 49 return true; 50 } 51 52 int main() { 53 memset(f,-1,sizeof(f)); 54 55 f[0] = 7; 56 f[1] = 11; 57 58 while(Do()); 59 return 0; 60 }
标签:
原文地址:http://www.cnblogs.com/ohyee/p/5513860.html