• <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>
            隨筆-19  評論-1  文章-0  trackbacks-0
            A triangle field is numbered with successive integers in the way shown on the picture below.



            The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller's route.

            Write the program to determine the length of the shortest route connecting cells with numbers N and M.
            #include <stdio.h>
            #include
            <math.h>
            int main()
            {
                
            int temp,n,m,s,flag=3,cn,cm,zb,yb,cc,k,sj;
                
            while(scanf("%d%d",&m,&n)==2 )
                
            {   
                    flag
            =3;  s=0;  k=0;
                    
            if(m>n) 
                    
            {
                        temp
            =m;  m=n;  n=temp;
                    }

                    cn
            =(int)ceil(sqrt(n));    //判斷n和m所在層數
                    cm=(int)ceil(sqrt(m));
                    cc
            =abs(cn-cm);        //判斷兩點層差
                    zb=m+(cn-1)*(cn-1)-(cm-1)*(cm-1);  //判斷m輻射到n層所及范圍的左邊界和右邊界
                    yb=zb+2*cc;
                     
                    
            if(n>=zb && n <=yb) //判斷n在m范圍所須步數
                    {
                        s
            =2*(cc);
                        k
            =1;
                    }

                    
            else
                    
            {    
                        
            if(n<zb)   //判斷n到m邊界及m點所須步數和
                            s=2*(cc)+abs(n-zb); 
                        
            else
                            s
            =2*(cc)+abs(n-yb);
                    }

                    sj
            =m-(cm-1)*(cm-1);   //判斷三角類型0正,1倒
                    if(abs(n-m)% 2 !=(cc) % 2)
                    
            {
                        
            if(sj % 2 ==1 )
                            flag
            =1;
                        
            else
                            flag
            =0;
                    }

                    
            if(flag==1 && k==1)
                        s
            =s-1;      //假如n點在m點輻射范圍內,正三角-1,倒三角+1,不在不判斷.
                    if(flag==0 && k==1
                        s
            =s+1;
                    printf(
            "%d\n",s);
                }

                
            return 0;
            }
            cn-1)*(cn-1)是1到n-1行末尾的數,也就是1-n的里面小三角形的個數~,
            (cm-1)*(cm-1);也是一樣的嘛~
            兩個相減就是m行的個數了!~ m加個數不就是左邊界了嘛~
            zb+兩倍的行差就是右邊界了!~
            而且正三角所到的邊界是正三角型,反三角所到的邊界是反三角型,這點要注意!

            posted on 2010-10-06 18:05 孟起 閱讀(1324) 評論(1)  編輯 收藏 引用 所屬分類: 水題

            評論:
            # re: HDU1030 Delta-wave 找規律 2010-11-11 15:23 | gdut
            我草,這題你也敢說水題....代碼copy別人的...  回復  更多評論
              
            久久天天躁狠狠躁夜夜不卡 | 伊人久久大香线蕉AV一区二区| 精品国产乱码久久久久久浪潮| 91久久精品视频| 日本高清无卡码一区二区久久 | 99久久这里只精品国产免费| 久久精品一本到99热免费| 久久人人爽人人爽人人片av高请| 国产精品99久久不卡| 欧美激情一区二区久久久| 国内精品久久国产大陆| 婷婷国产天堂久久综合五月| 精品久久无码中文字幕| 亚洲另类欧美综合久久图片区| 亚洲AV无一区二区三区久久| 久久精品亚洲乱码伦伦中文| 久久久久高潮毛片免费全部播放| 久久久久国产一区二区| 日本精品久久久中文字幕| 久久婷婷五月综合成人D啪| 国产农村妇女毛片精品久久| 久久久亚洲欧洲日产国码二区| 久久97久久97精品免视看| 久久91精品国产91久久麻豆| 亚洲国产另类久久久精品黑人| 香港aa三级久久三级老师2021国产三级精品三级在 | 亚洲AV无码久久精品色欲| 亚洲精品久久久www| 久久国产免费| 99久久免费国产精品| 亚洲成人精品久久| 久久国产精品99久久久久久老狼 | 久久亚洲高清观看| 青青草原综合久久大伊人精品| 97久久精品午夜一区二区| 99久久人妻无码精品系列| 久久久婷婷五月亚洲97号色| 久久天天躁狠狠躁夜夜躁2O2O| 成人妇女免费播放久久久| 97久久香蕉国产线看观看| 国产精品久久波多野结衣|