URAL1133. Fibonacci Sequence(二分)
刚开始还用记忆化推了下公式 后来发现数是非常大的
二分 然后就是精度错误 中间值会很大
乱七八糟的改
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<cmath> 7 #include<vector> 8 using namespace std; 9 #define LL long long 10 #define INF 2147483647 11 long double f[3010]; 12 int main() 13 { 14 LL i,j,s1,s2,t,n,g; 15 cin>>i>>s1>>j>>s2>>n; 16 i+=1005;j+=1005;n+=1005; 17 if(i>j) 18 { 19 t = i;i = j;j = t; 20 t = s1;s1 = s2; s2 = t; 21 } 22 f[i] = s1; 23 f[j] = s2; 24 if(j!=i+1) 25 { 26 long double low = -INF,high = INF,m; 27 while(low<high) 28 { 29 m = (low+high)/2; 30 f[i+1] = m; 31 for(g = i+2 ; g < j ; g++) 32 { 33 f[g] = f[g-1]+f[g-2]; 34 } 35 long double tt = f[j-1]+f[j-2]; 36 if(tt<s2) 37 low = m+1; 38 else if(tt>s2) 39 high = m-1; 40 else low=m,high=m; 41 } 42 f[i+1] = (low+high)/2; 43 for(g = i+2 ; g < j ; g++) 44 { 45 f[g] = f[g-1]+f[g-2]; 46 } 47 } 48 if(n<i) 49 { 50 for(g = i-1 ; g >= n ; g--) 51 f[g] = f[g+2]-f[g+1]; 52 } 53 else if(n>j) 54 { 55 for(g = j+1 ; g <= n ; g++) 56 f[g] = f[g-1]+f[g-2]; 57 } 58 cout<<(LL)f[n]<<endl; 59 return 0; 60 }