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

            poj1079

            Ratio

            Time Limit: 1000MS
            Memory Limit: 10000K
            Total Submissions: 3596
            Accepted: 1328

            Description

            If you ever see a televised report on stock market activity, you'll hear the anchorperson say something like ``Gainers outnumbered losers 14 to 9,'' which means that for every 14 stocks that increased in value that day, approximately 9 other stocks declined in value. Often, as you hear that, you'll see on the screen something like this:
            Gainers 1498
            Losers 902

            As a person with a head for numbers, you'll notice that the anchorperson could have said ``Gainers outnumbered losers 5 to 3'', which is a more accurate approximation to what really happened. After all, the exact ratio of winners to losers is (to the nearest millionth) 1.660754, and he reported a ratio of 14 to 9, which is 1.555555, for an error of 0.105199; he could have said ``5 to 3'', and introduced an error of only 1.666667-1.660754=0.005913. The estimate ``5 to 3'' is not as accurate as ``1498 to 902'' of course; evidently, another goal is to use small integers to express the ratio. So, why did the anchorperson say ``14 to 9?'' Because his algorithm is to lop off the last two digits of each number and use those as the approximate ratio.

            What the anchorman needs is a list of rational approximations of increasing accuracy, so that he can pick one to read on the air. Specifically, he needs a sequence {a_1, a_2, ..., a_n} where a_1 is a rational number with denominator 1 that most exactly matches the true ratio of winners to losers (rounding up in case of ties), a_{i+1} is the rational number with least denominator that provides a more accurate approximation than a_i, and a_n is the exact ratio, expressed with the least possible denominator. Given this sequence, the anchorperson can decide which ratio gives the best tradeoff between accuracy and simplicity.

            For example, if 5 stocks rose in price and 4 fell, the best approximation with denominator 1 is 1/1; that is, for every stock that fell, about one rose. This answer differs from the exact answer by 0.25 (1.0 vs 1.25). The best approximations with two in the denominator are 2/2 and 3/2, but neither is an improvement on the ratio 1/1, so neither would be considered. The best approximation with three in the denominator 4/3, is more accurate than any seen so far, so it is one that should be reported. Finally, of course, 5/4 is exactly the ratio, and so it is the last number reported in the sequence.

            Can you automate this process and help the anchorpeople?

            Input

            input contains several pairs of positive integers. Each pair is on a line by itself, beginning in the first column and with a space between the two numbers. The first number of a pair is the number of gaining stocks for the day, and the second number is the number of losing stocks for the day. The total number of stocks never exceeds 5000.

            Output

            For each input pair, the standard output should contain a series of approximations to the ratio of gainers to losers. The first approximation has '1' as denominator, and the last is exactly the ratio of gainers to losers, expressed as a fraction with least possible denominator. The approximations in between are increasingly accurate and have increasing denominators, as described above.
            The approximations for a pair are printed one to a line, beginning in column one, with the numerator and denominator of an approximation separated by a slash (``/''). A blank line separates one sequence of approximations from another.

            Sample Input

            5 4  1498 902 

            Sample Output

            1/1  4/3  5/4   2/1  3/2  5/3  48/29  53/32  58/35  63/38  68/41  73/44  78/47  83/50  88/53  93/56  377/227  470/283  563/339  656/395  749/451

            Source

            South Central USA 1998

            題目好長(zhǎng),沒(méi)看
            大體明白意思了,
            就是找與要求的數(shù)越來(lái)越接近的數(shù)
            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;
            #define maxn 5005
            #define eps 0.0001
            #define eps1 0.00000001
            int ans[maxn][2],num;
            double s1,s2,s3;
            int gcd(int a,int b)
            {
                
            if(b==0return a;
                
            else return gcd(b,a%b);
            }
            int main()
            {
                
            bool flag;
                flag
            =1;
                
            double x,y,u;
                
            int a,b,tmp,x1;
                
            while(scanf("%d%d",&a,&b)!=EOF)
                {
                    tmp
            =gcd(a,b);
                    a
            =a/tmp;
                    b
            =b/tmp;
                    num
            =0;
                    u
            =2.0;
                    s1
            =double(a)/double(b);
                    
            for(int i=1; i<=b; i++)
                    {
                        x
            =double(a*i)/double(b);
                        x1
            =(int)(x);
                        
            if(x-x1>=0.5)
                            x1
            ++;
                        s2
            =double(x1)/double(i);

                        
            if(fabs(s2-s1)<u)
                            
            if(gcd(x1,i)==1)
                            {
                                num
            ++;
                                ans[num][
            0]=x1;
                                ans[num][
            1]=i;
                                u
            =fabs(s2-s1);
                            }
                    }
                    
            if(!flag) printf("\n");
                    
            for(int i=1; i<=num; i++)
                        printf(
            "%d/%d\n",ans[i][0],ans[i][1]);
                    
            if(flag) flag=0;
                }
                
            return 0;
            }

            posted on 2012-07-30 21:42 jh818012 閱讀(367) 評(píng)論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            国产成人99久久亚洲综合精品| 亚洲国产精品无码久久青草| 天堂久久天堂AV色综合| 精品久久久久久无码中文字幕一区 | 久久精品一区二区三区中文字幕| 岛国搬运www久久| 午夜视频久久久久一区| 色综合久久无码五十路人妻| 欧美亚洲国产精品久久蜜芽| 欧美粉嫩小泬久久久久久久 | 色88久久久久高潮综合影院| 91亚洲国产成人久久精品| 伊人久久无码精品中文字幕| 久久线看观看精品香蕉国产| 国产香蕉久久精品综合网| 久久亚洲国产精品一区二区| 亚洲人成网亚洲欧洲无码久久 | 久久婷婷国产综合精品| 欧美日韩成人精品久久久免费看| 国产亚洲欧美成人久久片| 一级做a爰片久久毛片看看| AV狠狠色丁香婷婷综合久久| 久久久久久久亚洲Av无码| 亚洲国产香蕉人人爽成AV片久久| 青青青国产成人久久111网站| 中文字幕无码免费久久| 伊人久久大香线蕉精品不卡| 国产精品欧美亚洲韩国日本久久 | 久久天天婷婷五月俺也去| 伊人热人久久中文字幕| 久久国产色AV免费观看| 伊人久久大香线焦AV综合影院| 香港aa三级久久三级老师2021国产三级精品三级在 | 精品久久8x国产免费观看| 伊人久久大香线蕉av不变影院| 国产欧美久久久精品影院| 色婷婷狠狠久久综合五月| 久久精品国产99久久久香蕉| 久久久WWW免费人成精品| 日韩精品无码久久一区二区三| 国产精品gz久久久|