标签:技术 fine 无法 onclick ++ none bit def fibonacci
乍看数据极大,实则暗藏玄机。
原本想通过Baidu找一下O(1)的通项公式,
结果发现根本无法实现:
但是我却发现了这个:
兴奋之情溢于言表,不说了,放代码:
1 #include<bits/stdc++.h> 2 #define fi fifteen 3 using namespace std; 4 unsigned long long fifteen[15005],c[15000]; 5 int x,y,T; 6 void yu() 7 { 8 fi[0]=0;fi[1]=1; 9 for(int i=2;i<=15000;i++) 10 { 11 fi[i]=(fi[i-1]+fi[i-2])%10000; 12 //cout<<fi[i]<<endl; 13 } 14 //cout<<fi[127]<<" "; 15 } 16 void add() 17 { 18 for(int i=1;i<=15000;i++) 19 { 20 int ii; 21 ii=i; 22 while(ii<=15000) 23 { 24 c[ii]+=fi[i]%10000; 25 c[ii]=c[ii]%10000; 26 ii+=ii&(-ii);//cout<<"c"<<c[4]; 27 //cout<<c[ii]<<" "; 28 } 29 } 30 31 } 32 int ask(long long op) 33 { 34 int ans=0; 35 op=op%15000; 36 while(op>0) 37 { 38 ans+=c[op]%10000; 39 op-=op&(-op); 40 //cout<<"op:"<<c[op]<<" "; 41 //cout<<ans; 42 } 43 //cout<<"ans:"<<ans<<endl; 44 return ans%10000; 45 } 46 int main() 47 { 48 memset(fifteen,0,sizeof(fifteen)); 49 yu(); 50 add(); 51 cin>>T; 52 for(int i=1;i<=T;i++) 53 { 54 long long x,y,ll; 55 scanf("%lld%lld",&x,&y); 56 ll=ask(y)-ask(x-1); 57 if((ll)<0) 58 { 59 ll+=10000; 60 } 61 printf("%d\n",ll); 62 } 63 return 0; 64 }
当老师讲的时候,却利用了矩阵乘法(Baidu)
标签:技术 fine 无法 onclick ++ none bit def fibonacci
原文地址:https://www.cnblogs.com/HHHG/p/11165118.html