The main idea: Define a sequence, f[i] = f[i/2] (i% 2 = = 0); F[i] = F[i/2] + F[I/2 + 1] (i 2 = = 1); Find the item m of this sequence (M <= 10 ^ 100)
Idea: Data range high precision did not run. Remember to do this before the weakening version of the problem, it seems that there is no high-precision memory search, the problem is to add a high precision.
CODE:
#include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm > #define MAX 210#define MO 10using namespace std; #define MAX (a) (a) > (b)? (a):(B)) class Bigint{private:int Num[max],len;public:bigint (int _ = 0) {memset (num,0,sizeof (num)); Num[len = 1] = _; } void Read () {static char S[max]; scanf ("%s", s); Len = strlen (s); for (int i = 1; I <= len; ++i) num[i] = s[len-i]-' 0 '; } Friend Ostream &operator << (ostream &os,const BigInt &a); BOOL operator < (const BIGINT &a) Const {if (len = = A.len) {for (int i = len; i; i.) if (num[i]! = A.num[i]) return num[i] < a.num[i]; } return Len < A.len; } bool Odd () const {return num[1]&1; } BIGINT operator + (const BIGINT &a) const {BIGINT re; Re.len = max (Len,a.len); INT TEMP = 0; for (int i = 1; I <= Re.len; ++i) {Re.num[i] = temp + num[i] + a.num[i]; temp = re.num[i]/MO; Re.num[i]%= MO; } if (temp) re.num[++re.len] = temp; return re; } BigInt operator/(int c) const {BIGINT re; Re.len = Len; int temp = 0; for (int i = len; i; i.) {Re.num[i] = (Num[i] + temp)/2; temp = (Num[i] + temp)% 2 * MO; } while (!re.num[re.len])--re.len; return re; }}temp; Ostream &operator << (ostream &os,const BigInt &a) {OS << a.num[a.len]; for (int i = a.len-1; i; i) OS << a.num[i]; return OS;} Map<bigint,bigint> G; int T; BigInt &memorialsearch (const BigInt &a) {if (G.find (a)! = G.end ()) return g[a]; if (a.odd ()) g[a] = Memorialsearch (A/2) + memorialsearch (A/2 + 1); else G[a] = Memorialsearch (A/2); return g[a];} int main () {g[0] = BigInt (0); G[1] = BigInt (1); For (Cin >> T; t--;) {Temp. Read (); cout << Memorialsearch (temp) << Endl; } return 0;}
Bzoj 2656 Zjoi 2012 series (sequence) high accuracy + memory search