• <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>
            posts - 43,  comments - 9,  trackbacks - 0

            http://acm.cs.bupt.cn/onlinejudge/showproblem.php?problem_id=1379

            給一個(gè)長度10MB的大數(shù)n,要求計(jì)算ceil(n/2),內(nèi)存只有1000K,顯然不能開數(shù)組,要邊讀邊除
            通常的除法只要設(shè)個(gè)變量記錄每位是否整除(mod).此外題目要求不輸出前導(dǎo)0,再設(shè)個(gè)bool值記錄(zero)
            特殊之處在于向上取整.舉個(gè)例子:1999/2=1000,顯然直接除一位輸出一位有問題
            關(guān)鍵之處在于增加一個(gè)變量記錄連續(xù)的9的個(gè)數(shù)(cnt9).如果處理到非9的位,或者輸入文件結(jié)束,就分情況輸出前面最近一位非9數(shù)除的結(jié)果,然后循環(huán)輸出9除的結(jié)果.因此,還要一個(gè)變量記錄上一位除得的商(co)

             1 /*
             2     記錄連續(xù)9的個(gè)數(shù),為了使輸入末尾有連續(xù)9時(shí)向上取整
             3     co記錄上位除的商
             4     mod記錄上位除的余數(shù)
             5     cnt9記錄連續(xù)的9的個(gè)數(shù)
             6     zero記錄前導(dǎo)是否為0 
             7     當(dāng)前位不是9時(shí),輸出之前的結(jié)果,并將當(dāng)前位+mod*5存入co
             8     當(dāng)前位是9時(shí),cnt9++
             9     輸入結(jié)束時(shí),處理末尾幾位 
            10     注意:
            11         輸入為0時(shí)
            12         以9開頭時(shí)
            13         以x9開頭時(shí) 
            14     
            15     幾組數(shù)據(jù): 
            16     000319900099 159950050
            17     199 100
            18     0199 100
            19     1998 999
            20     99 50
            21     0 0
            22 */
            23 #include <iostream>
            24 using namespace std;
            25 int main(){
            26     bool zero;
            27     int mod,cnt9;
            28     char co,cn,ct;
            29     zero=true; mod=0; co=0; cnt9=0;
            30     while(isdigit(cn=getchar())){
            31         cn-='0';
            32         if(cn!=9){
            33             if(!zero||co){
            34                 zero=false;
            35                 putchar(co+'0');
            36             }
            37             if(cnt9)zero=false;
            38             while(cnt9--){
            39                 putchar(4+5*mod+'0');
            40                 mod=1;
            41             }
            42             cnt9=0;
            43             co=(cn>>1)+5*mod;
            44             mod=cn&1;
            45         }
            46         else{
            47             cnt9++;
            48         }
            49     }
            50     if(!zero||co||mod){
            51         zero=false;
            52         putchar(co+mod+'0');
            53     }
            54     mod=1-mod;
            55     if(cnt9)zero=false;
            56     while(cnt9--){
            57         putchar(5*mod+'0');
            58         mod=0;
            59     }
            60     //輸入0的情況!
            61     if(zero)putchar('0'); 
            62     putchar('\n');
            63     return 0;
            64 }
            65 

            posted on 2009-03-25 22:52 wolf5x 閱讀(268) 評論(0)  編輯 收藏 引用 所屬分類: acm_icpc
            <2009年3月>
            22232425262728
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            "Do not spend all your time on training or studying - this way you will probably become very exhausted and unwilling to compete more. Whatever you do - have fun. Once you find programming is no fun anymore – drop it. Play soccer, find a girlfriend, study something not related to programming, just live a life - programming contests are only programming contests, and nothing more. Don't let them become your life - for your life is much more interesting and colorful." -- Petr

            留言簿(3)

            隨筆分類(59)

            隨筆檔案(43)

            cows

            搜索

            •  

            最新評論

            評論排行榜

            久久无码AV中文出轨人妻| 久久亚洲春色中文字幕久久久| 2020国产成人久久精品| 久久久久四虎国产精品| 色欲综合久久躁天天躁蜜桃| 伊人久久大香线蕉AV一区二区| 久久精品一区二区三区中文字幕| 国内精品久久久久影院日本| 久久午夜夜伦鲁鲁片免费无码影视| 国产精品日韩深夜福利久久| 久久亚洲国产精品一区二区| 精品久久久久久久| 色综合久久久久网| 国产精品九九久久精品女同亚洲欧美日韩综合区| 久久精品国产日本波多野结衣| 久久人妻无码中文字幕| 亚洲国产另类久久久精品小说 | 久久亚洲国产欧洲精品一| 热re99久久6国产精品免费| 99久久99久久精品免费看蜜桃| 97精品国产97久久久久久免费 | 久久国产精品久久| 伊人色综合久久天天| 国内精品欧美久久精品| 国产综合免费精品久久久| 久久天天躁狠狠躁夜夜av浪潮| 色婷婷久久久SWAG精品| 亚洲精品乱码久久久久久久久久久久| 欧洲精品久久久av无码电影| 久久青青草原精品影院| 久久99精品九九九久久婷婷| 久久综合九色综合网站| 久久99国产乱子伦精品免费| 国产农村妇女毛片精品久久| 国产精品久久久久久久久软件| 久久久久久无码Av成人影院| 久久精品成人免费观看97| 色欲久久久天天天综合网| 一本久久a久久精品综合夜夜 | 久久精品桃花综合| 久久精品国产精品亚洲精品|