ZOJ 3702 Fibonacci
解题思路:
找规律,不难的,打表
坑的地方在于题目限定条件
and the seed value for G(1) is a random integer t, (t>=1)
虽然都用粗体表示出来了= = 但我还是没注意到 = =
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main(){ int numCase , i ,j ,t ,G; long long b[30]; int array[30]; array[0] = 0; array[1] = 1; for(i = 2 ; i <= 20 ; i++) array[i] = array[i-1] + array[i-2]; scanf("%d",&numCase); while(numCase--){ memset(b,0,sizeof(b)); scanf("%d%d%d",&i,&G,&j); if((G - array[i-1]) % array[i] == 0 && (G - array[i-1]) / array[i] >= 1){ // 满足存在t 并且,由题意可得 t>=1 t = (G - array[i-1]) / array[i]; b[0] = 1; b[1] = t; for(int k = 2 ; k <= 20 ; k++) b[k] = b[k-1] + b[k-2]; printf("%lld\n",b[j]); } else{ printf("-1\n"); } } return 0; }