• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨(dú)家記憶

            一段永遠(yuǎn)封存的記憶,隨風(fēng)而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            P2413——高精度

            Posted on 2008-09-03 16:19 Hero 閱讀(153) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
              1 //2413 Accepted 880K 32MS G++ 3264B  PKU
              2 
              3 #include <iostream>
              4 #include <cmath>
              5 using namespace std;
              6 
              7 const int Base=1000000000;
              8 const int Capacity=200;
              9 typedef long long llong;
             10 
             11 struct BigInt{
             12     int Len;
             13     int Data[Capacity];
             14     BigInt():Len(0){}
             15     BigInt(const BigInt &V):Len(V.Len){memcpy(Data,V.Data,Len*sizeof*Data);}
             16     BigInt(int V):Len(0){for(;V>0;V/=Base) Data[Len++]=V%Base;}
             17     BigInt &operator=(const BigInt &V){Len=V.Len;memcpy(Data,V.Data,Len*sizeof*Data);return *this;}
             18     int &operator[](int Index){return Data[Index];}
             19     int operator[](int Index)const{return Data[Index];}
             20 };
             21 int compare(const BigInt &A,const BigInt &B){
             22     if(A.Len!=B.Len) return A.Len>B.Len ? 1:-1;
             23     int i;
             24     for(i=A.Len-1;i>=0 && A[i]==B[i];i--);
             25     if(i<0)return 0;
             26     return A[i]>B[i] ? 1:-1;
             27 }
             28 BigInt operator+(const BigInt &A,const BigInt &B){
             29     int i,Carry(0);
             30     BigInt R;
             31     for(i=0;i<A.Len||i<B.Len||Carry>0;i++){
             32         if(i<A.Len) Carry+=A[i];
             33         if(i<B.Len) Carry+=B[i];;
             34         R[i]=Carry%Base;
             35         Carry/=Base;
             36     }
             37     R.Len=i;
             38     return R;
             39 }
             40 BigInt operator-(const BigInt &A,const BigInt &B){
             41     int i,Carry(0);
             42     BigInt R;
             43     R.Len=A.Len;
             44     for(i=0;i<R.Len;i++){
             45         R[i]=A[i]-Carry;
             46         if(i<B.Len) R[i]-=B[i];
             47         if(R[i]<0) Carry=1,R[i]+=Base;
             48         else Carry=0;
             49     }
             50     while(R.Len>0&&R[R.Len-1]==0) R.Len--;
             51     return R;
             52 }
             53 BigInt operator*(const BigInt &A,const int &B){
             54     int i;
             55     llong Carry(0);
             56     BigInt R;
             57     for(i=0;i<A.Len||Carry>0;i++){
             58         if(i<A.Len) Carry+=llong(A[i])*B;
             59         R[i]=Carry%Base;
             60         Carry/=Base;
             61     }
             62     R.Len=i;
             63     return R;
             64 }
             65 istream &operator>>(istream &In,BigInt &V){
             66     char Ch;
             67     for(V=0;In>>Ch;){
             68         V=V*10+(Ch-'0');
             69         if(In.peek()<=' 'break;
             70     }
             71     return In;
             72 }
             73 ostream &operator<<(ostream &Out,const BigInt &V){
             74     int i;
             75     Out<<(V.Len==0 ? 0:V[V.Len-1]);
             76     for(i=V.Len-2;i>=0;i--for(int j=Base/10;j>0;j/=10) Out<<V[i]/j%10;
             77     return Out;
             78 }
             79 
             80 
             81 BigInt Bint0(0) ;
             82 BigInt Bint1(1) ;
             83 
             84 BigInt ina, inb ;
             85 
             86 const int size = 600 ;
             87 BigInt fib[size] ;
             88 
             89 void process()
             90 {    
             91     int left = 1int right = size-1 ; int mid ;
             92 
             93     while( left < right )
             94     {
             95         mid = (left+right)>>1 ;
             96         if( compare(fib[mid], ina) >= 0 ) right = mid ;
             97         else left = mid + 1 ;
             98     }
             99     //if( compare(fib[right], ina) >= 0 ) left = right ;
            100 
            101     int sn = right ;
            102 
            103     left = sn ; right = size-1 ;
            104 
            105     while( left < right )
            106     {
            107         mid = ((left+right)/2) ;
            108         if( compare(fib[mid], inb)<=0 ) left = mid+1 ;
            109         else    right = mid ;
            110     }
            111     //if( compare(fib[right], inb)<=0 ) left = right ;
            112 
            113     int en = right ;
            114 
            115 
            116     printf( "%d\n", en - sn ) ;
            117 }
            118 
            119 void process1()
            120 {
            121     int sn = 1 ; int en ;
            122     
            123     for( ; sn<size; sn++ )
            124     {
            125         if( compare(fib[sn], ina)>= 0 ) break ;
            126     }
            127     for( en=sn; en<size; en++ )
            128     {
            129         if( compare(fib[en], inb)>0 ) break ;
            130     }
            131 
            132     printf( "%d\n", en-sn ) ;
            133 }
            134 
            135 int main()
            136 {
            137     //cout << Bint0 << Bint1 << endl ;
            138 
            139     fib[1= Bint1 ; fib[2= Bint1 * 2 ;
            140     forint i=3; i<size; i++ )
            141     {
            142         fib[i] = fib[i-2+ fib[i-1] ;
            143     }
            144 
            145     while( cin>>ina>>inb )    
            146     {
            147         //cout << ina << inb << endl ;
            148         if( compare(ina, Bint0)==0 && compare(inb, Bint0)==0 ) break ;
            149 
            150         process() ;
            151 
            152         //output() ;
            153     }
            154 
            155     return 0 ;
            156 }
            久久精品亚洲精品国产色婷| 精品一区二区久久| 欧美日韩精品久久久久| 久久久久久久97| 久久亚洲精精品中文字幕| 久久毛片免费看一区二区三区| 色欲av伊人久久大香线蕉影院| 久久综合九色综合久99| 91久久精品视频| 国产精品久久久久国产A级| 久久er99热精品一区二区| 久久久久久久亚洲Av无码| 五月丁香综合激情六月久久| 模特私拍国产精品久久| 国产精品日韩欧美久久综合| 久久久91精品国产一区二区三区 | 久久久噜噜噜www成人网| 久久天天日天天操综合伊人av| 精品久久久久久99人妻| 久久99精品国产99久久6| 亚洲国产成人久久综合区| 人妻无码αv中文字幕久久 | 国产精品久久成人影院| 99国产精品久久| 69SEX久久精品国产麻豆| 精品乱码久久久久久夜夜嗨| 九九热久久免费视频| 热RE99久久精品国产66热| 亚洲AV无码久久精品成人| 久久久久久狠狠丁香| 久久综合久久性久99毛片| 思思久久精品在热线热| 久久人人爽人人爽人人片AV东京热 | 99久久夜色精品国产网站| 无码人妻久久一区二区三区| 国产精品欧美久久久久无广告 | 一极黄色视频久久网站| 久久精品中文字幕久久| 国产精品美女久久久久网| 日韩精品久久久肉伦网站| 色欲av伊人久久大香线蕉影院|