• <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>

            Brian Warehouse

            Some birds aren`t meant to be caged, their feathers are just too bright... ...
            posts - 40, comments - 16, trackbacks - 0, articles - 1

            POJ 1001 Exponentiation

            Posted on 2010-08-17 14:02 Brian 閱讀(288) 評(píng)論(0)  編輯 收藏 引用 所屬分類: POJ

            分類開(kāi)篇語(yǔ): 第一個(gè)程序搞了好幾天,發(fā)現(xiàn)了很多問(wèn)題。POJ不保證按順序做且更新速度肯定不會(huì)很快。有些題自己做不出來(lái)借鑒別人的會(huì)注明出處。很多算法都需要從網(wǎng)上找,第一題的大浮點(diǎn)數(shù)相乘的核心算法就是這樣找來(lái)的。我心里明白,雖然AC了,但是邊緣數(shù)據(jù)處理的很粗糙,我自己都發(fā)現(xiàn)幾個(gè)bug了,但是依然AC了。

            本題主要注意將字符串轉(zhuǎn)化為實(shí)際的數(shù)字然后借鑒數(shù)制的思想來(lái)進(jìn)行大數(shù)相乘。

            Description

            Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

            This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

            Input

            The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

            Output

            The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

            Sample Input

            95.123 12
            0.4321 20
            5.1234 15
            6.7592  9
            98.999 10
            1.0100 12
            

            Sample Output

            548815620517731830194541.899025343415715973535967221869852721
            .00000005148554641076956121994511276767154838481760200726351203835429763013462401
            43992025569.928573701266488041146654993318703707511666295476720493953024
            29448126.764121021618164430206909037173276672
            90429072743629540498.107596019456651774561044010001
            1.126825030131969720661201
            編譯器C++ 源碼:
            #include <iostream>
            #include <string>
            using namespace std;
            #define MAX 255
             
            int getnum(string s,int *c) // get real number of R
            {
                int i=0,j=0,t[MAX];
                memset(t,0,sizeof(int)*MAX); // a stores 0
               
             while (i < 6) // R value 1 through 6
             {
              if (s[i] != '.')
              {
               t[j]=s[i]-'0';
               j++;
              }   
              i++;
             }     // a`s length = 5
               
             for (j=0; j<5; j++)
              c[j]=t[4-j]; // c stores in order from a
              
             for (i=0; s[i] != '.'; i++); // find decimal point
             return (5-i); // the position of . point
            }
             
            void multi(int *a,int *b) // big-multiplication
            {
                int i=0,j,r=0,t[MAX];
                memset(t,0,sizeof(int)*MAX); // t stores 0
               
             for (; i<5; i++)
              for (j=0; j<255; j++)
               t[i+j] += a[i]*b[j]; // core algorithms!
             
             for (i=0; i<255; i++)
             {
              b[i]=(r+t[i])%10; // r always stores remainder
              r=(r+t[i])/10;   // b stores the result
             }    
            }    // basic algorithms of b-m
            int main() 
            {
                int i,j,d_pos,n,a[MAX],b[MAX];
                string s;
                while (cin>>s>>n)
             {
              
              memset(b,0,sizeof(int)*MAX);
              memset(a,0,sizeof(int)*MAX);
              d_pos=getnum(s,a);
              getnum(s,b);
              
              for (i=0; i<n-1; i++)
               multi(a,b);  // a is a loop invariant
              
              for (i=254; !b[i]; i--); //find last non-zero  
              for (j=0; !b[j]; j++); // find first non-zero
              
              for (; i >= n*d_pos; i--) // loop n times
               cout<<b[i];
              if (n*d_pos >= j+1) cout<<"."; //pay attention
              for (i=n*d_pos-1; i>=j; i--)
               cout<<b[i];  //from back formating output
              
              cout<<endl;
             }
             return 0;
            }
            亚洲精品高清一二区久久| 久久青青草原亚洲av无码| 无码AV中文字幕久久专区| 久久久久久精品成人免费图片| 精品国产乱码久久久久久人妻| 国产亚洲美女精品久久久久狼| 丰满少妇人妻久久久久久4| 久久精品一本到99热免费| 久久精品国产福利国产秒| 亚洲伊人久久成综合人影院 | 中文字幕乱码久久午夜| 久久香蕉一级毛片| 精品国产乱码久久久久久呢| 丁香久久婷婷国产午夜视频| 久久久久成人精品无码中文字幕 | 亚洲欧美日韩精品久久亚洲区| 精品蜜臀久久久久99网站| 一级做a爰片久久毛片毛片| 草草久久久无码国产专区| 婷婷五月深深久久精品| 久久久久久久综合狠狠综合| 久久99国产精品久久99| 久久综合给合久久国产免费| 久久精品免费全国观看国产| 久久青青草原精品国产软件| 国产精品一区二区久久精品无码| 99久久国语露脸精品国产| 久久久噜噜噜久久熟女AA片| 狠狠色婷婷久久一区二区| 久久久久久久精品成人热色戒| 久久中文字幕视频、最近更新| 精品一久久香蕉国产线看播放| 婷婷综合久久中文字幕| 91精品国产高清久久久久久国产嫩草 | 色噜噜狠狠先锋影音久久| 久久久久无码精品国产| 国产午夜福利精品久久2021| 国内精品久久久久影院日本| 久久国产乱子伦免费精品| 丁香狠狠色婷婷久久综合| 欧美久久精品一级c片片|