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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年12月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

            題目地址:
                     http://acm.hdu.edu.cn/showproblem.php?pid=2199
            題目描述:
                     
            Can you solve this equation?

            Time Limit: 
            2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
            Total Submission(s): 
            322    Accepted Submission(s): 148


            Problem Description
            Now,given the equation 
            8*x^4 + 7*x^3 + 2*x^2 + 3*+ 6 == Y,can you find its solution between 0 and 100;
            Now please 
            try your lucky.
             

            Input
            The first line of the input contains an integer T(
            1<=T<=100) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10);
             

            Output
            For each test 
            case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.
             

            Sample Input
            2
            100
            -4
             

            Sample Output
            1.6152
            No solution
            !

            題目分析:
            很明顯,這是一個(gè)2分搜索的題目, 但是注意下題目的數(shù)據(jù)!! 1e10 的實(shí)數(shù)!! 而且精度是要求在 0.0001 . 所以就算是2分?jǐn)?shù)據(jù)量依舊比較大,如果用
            通常的遞歸方法嗎很遺憾 , RE了.............  沒(méi)辦法, 只能循環(huán)了.
            下面的是遞歸 RE 的代碼 :
            #include <iostream>
            #include <cmath>
            using namespace std;
            #define POW(x) ( (x) * (x) )
            #define POW3(x) ( POW(x) * (x) )
            #define POW4(x) ( POW(x) * POW(x) )
            double y = 0;
            bool douEql ( double a,double b )
            {
            if ( fabs( a - b ) <= 1e-6  )
            return  true;
            return false;
            }
            double cal ( double n )
            {
            return 8.0 * POW4(n) + 7 * POW3(n) + 2 * POW(n) + 3 * n + 6 ;
            }
            double biSearch ( double l, double r )
            {
            if ( douEql ( l,r ) )
            {
            if ( douEql ( y, cal ( l ) ) )
            return l;
            return -1;
            }
            double mid = ( l + r ) / 2.0;
            if ( douEql ( y, cal ( mid ) ) )
            return mid;
            else if ( cal ( mid ) > y )
            return biSearch ( l,mid - 0.0001 );
            else
            return biSearch ( mid + 0.0001, r );
            }
            int main ()
            {
            int T;
            scanf ( "%d",&T );
            while ( T -- )
            {
            scanf ( "%lf",&y );
            if ( cal(0) >= y && cal(100) <= y )
            {
            printf ( "No solution!\n" );
            continue;
            }
            double res = biSearch ( 0.0, 100.0 );
            if ( res == -1 )
            printf ( "No solution!\n" );
            else
            printf ( "%.4lf\n",res );
            }
            return 0;
            }

            AC代碼如下:
            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

            #include 
            <iostream>
            #include 
            <cmath>
            using namespace std;
            #define POW(x) ( (x) * (x) )
            #define POW3(x) ( POW(x) * (x) )
            #define POW4(x) ( POW(x) * POW(x) )
            double y = 0;
            double cal ( double n )
            {
                   
            return 8.0 * POW4(n) + 7 * POW3(n) + 2 * POW(n) + 3 * n + 6 ;
            }
            int main ()
            {
                
            int T;
                scanf ( 
            "%d",&T );
                
            while ( T -- )
                {
                      scanf ( 
            "%lf",&y );
                      
            if ( cal(0> y || cal(100< y )
                      {
                           printf ( 
            "No solution!\n" );
                           
            continue;
                      }
                      
            double l = 0.0, r = 100.0,res = 0.0;
                      
            while ( r - l > 1e-6 )
                      {
                            
            double mid = ( l + r ) / 2.0;
                            res 
            = cal ( mid );
                            
            if ( res > y )
                                 r 
            = mid - 1e-6;    
                            
            else 
                                 l 
            = mid + 1e-6;
                      }
                      printf ( 
            "%.4lf\n",( l + r ) / 2.0 ); 
                }
                
            return 0
            }
            久久99精品国产99久久6男男| 亚洲精品久久久www| 中文字幕久久波多野结衣av| 久久精品国产精品亚洲精品| 精品乱码久久久久久久| 九九久久精品国产| 蜜臀av性久久久久蜜臀aⅴ | 国产精品成人久久久| 亚洲精品无码久久久久去q| 91久久精一区二区三区大全| 欧美精品福利视频一区二区三区久久久精品 | 精品久久久久久无码中文字幕| 少妇人妻综合久久中文字幕| 狠狠干狠狠久久| 7777久久久国产精品消防器材 | 国产精品美女久久久m| 亚洲精品tv久久久久| 日韩一区二区久久久久久| 亚洲色婷婷综合久久| 一级女性全黄久久生活片免费| 久久九九亚洲精品| 久久se精品一区精品二区| 久久婷婷五月综合国产尤物app | 日韩精品久久久久久久电影| 久久这里只精品国产99热| 久久婷婷国产剧情内射白浆| 久久精品无码一区二区三区免费 | 久久久久久国产精品无码超碰| 亚洲精品午夜国产va久久| 久久伊人色| 久久人人青草97香蕉| 日韩精品久久久久久久电影| 久久精品视频91| 天天综合久久一二三区| 日本亚洲色大成网站WWW久久| 久久性精品| 久久这里只精品99re66| 久久无码AV一区二区三区| 国内精品伊人久久久影院 | 一本大道久久香蕉成人网| 欧洲国产伦久久久久久久|