• <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 孟起 閱讀(1321) 評論(1)  編輯 收藏 引用 所屬分類: 水題

            評論:
            # re: HDU1030 Delta-wave 找規律 2010-11-11 15:23 | gdut
            我草,這題你也敢說水題....代碼copy別人的...  回復  更多評論
              
            久久精品国产精品亚洲艾草网美妙| 成人久久精品一区二区三区 | 国产成人精品久久综合| 精品国产91久久久久久久 | 久久99国产精品久久久| 91精品国产色综久久| 丁香色欲久久久久久综合网| 人妻精品久久久久中文字幕69| 久久久91精品国产一区二区三区| 国产午夜电影久久| 久久人人爽人人爽人人片AV麻烦| 波多野结衣中文字幕久久| 日韩欧美亚洲综合久久影院Ds| 国产毛片欧美毛片久久久 | 久久久久久国产精品美女| 国产成人无码精品久久久免费| 国内精品久久久久影院亚洲| 久久线看观看精品香蕉国产| 亚洲va中文字幕无码久久| 久久黄色视频| 国产精久久一区二区三区| 国产精品无码久久久久久| 精品久久亚洲中文无码| 欧美午夜A∨大片久久 | 国产麻豆精品久久一二三| 久久九九兔免费精品6| 亚洲国产成人久久笫一页| 嫩草影院久久99| 久久精品国产福利国产秒| 久久午夜无码鲁丝片| 99久久国产宗和精品1上映| 亚洲国产成人久久综合野外| 久久精品一区二区三区中文字幕 | 久久99国产综合精品女同| 无码专区久久综合久中文字幕| 久久婷婷午色综合夜啪| 怡红院日本一道日本久久| 久久婷婷五月综合97色一本一本 | 午夜精品久久久久久久无码| 久久久久国产日韩精品网站| 久久久久亚洲AV成人网人人软件|