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

            USACO Section 3.3 Home on the Range

            Home on the Range

            Farmer John grazes his cows on a large, square field N (2 <= N <= 250) miles on a side (because, for some reason, his cows will only graze on precisely square land segments). Regrettably, the cows have ravaged some of the land (always in 1 mile square increments). FJ needs to map the remaining squares (at least 2x2 on a side) on which his cows can graze (in these larger squares, no 1x1 mile segments are ravaged).

            Your task is to count up all the various square grazing areas within the supplied dataset and report the number of square grazing areas (of sizes >= 2x2) remaining. Of course, grazing areas may overlap for purposes of this report.

            PROGRAM NAME: range

            INPUT FORMAT

            Line 1: N, the number of miles on each side of the field.
            Line 2..N+1: N characters with no spaces. 0 represents "ravaged for that block; 1 represents "ready to eat".

            SAMPLE INPUT (file range.in)

            6
            101111
            001111
            111111
            001111
            101101
            111001
            

            OUTPUT FORMAT

            Potentially several lines with the size of the square and the number of such squares that exist. Order them in ascending order from smallest to largest size.

            SAMPLE OUTPUT (file range.out)

            2 10
            3 4
            4 1  
            Analysis

            It is really a dynamic problem rather than a geometry problem, which is appeared at first time. However, it is easy to contribute a dynamic function later to replace older method.
            Initially, map[i][j], established by initial input, stands for the minimum length of a square, which its left-top point is (i,j). And, for the nearby points (i+1,j), (i,j+1) and (i+1,j+1),if all avaliable, map[i][j] can be expanded by these three points since map[i][j] is truly depended on these three values.
            What's more, considering the avaliable one for (i,j) is the minimum of these, then map[i][j]=min{map[i+1][j],map[i][j+1],map[i+1][j+1]}+1.
            Additionally, only is the function hold when all of the four points is avaliable!

            Code

            /*
            ID:braytay1
            PROG:range
            LANG:C++
            */

            #include 
            <iostream>
            #include 
            <fstream>
            #include 
            <string>
            using namespace std;

            int n;
            int g[250][250],sum[251];
            int min(int a,int b,int c){
                
            if (a>b) return (b>c)?c:b;
                
            else return (a>c)?c:a;
            }

            int main(){
                ifstream fin(
            "range.in");
                ofstream fout(
            "range.out");
                fin
            >>n;
                
            string tmp;
                memset(g,
            0,sizeof g);
                
            for (int i=0;i<n;i++){
                    fin
            >>tmp;
                    
            for (int j=0;j<n;j++){
                        g[i][j]
            =(tmp[j]=='1')?1:0;
                    }

                    tmp.clear();
                }
                
                
            for (int i=n-2;i>=0;i--)
                    
            for (int j=n-2;j>=0;j--){
                        
            if (g[i][j]&&g[i+1][j]&&g[i][j+1]&&g[i+1][j+1])
                            g[i][j]
            =min(g[i+1][j],g[i][j+1],g[i+1][j+1])+1;
                    }

                memset(sum,
            0,sizeof sum);
                
            for (int i=0;i<n-1;i++)
                    
            for (int j=0;j<n-1;j++){
                        
            int s;
                        s
            =g[i][j];
                        sum[s]
            ++;
                    }
             
                
            for (int i=2;i<=n;i++){
                    
            for (int j=i+1;j<=n;j++){
                        sum[i]
            +=sum[j];
                    }

                }

                
            for (int i=2;i<=n;i++)
                    
            if (sum[i]) fout<<i<<" "<<sum[i]<<endl;
                
            return 0;
            }


            posted on 2008-08-28 23:43 幻浪天空領主 閱讀(264) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            99久久人妻无码精品系列| 久久精品亚洲精品国产欧美| 亚洲成色WWW久久网站| 国产精品久久久久久久久鸭 | 波多野结衣久久一区二区| 久久WWW免费人成一看片| 9191精品国产免费久久| 热99RE久久精品这里都是精品免费| 久久综合精品国产二区无码| 久久99精品国产麻豆不卡| 99蜜桃臀久久久欧美精品网站 | 日日噜噜夜夜狠狠久久丁香五月 | 精品久久久噜噜噜久久久| 久久综合伊人77777| 99久久免费国产特黄| 久久无码AV一区二区三区| 一级做a爱片久久毛片| 国产精品一区二区久久| 久久午夜夜伦鲁鲁片免费无码影视| 精品久久久久久久久中文字幕| 久久久SS麻豆欧美国产日韩| 久久这里有精品视频| 精品多毛少妇人妻AV免费久久| 国内精品久久人妻互换| 久久精品亚洲一区二区三区浴池| 中文成人无码精品久久久不卡| 欧美日韩中文字幕久久久不卡| 久久国产精品成人免费| 91精品国产高清91久久久久久| 亚洲狠狠婷婷综合久久蜜芽| 久久久久免费精品国产| 欧美精品乱码99久久蜜桃| 久久99热这里只有精品66| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 97久久国产综合精品女不卡| 亚洲人成无码www久久久| 久久婷婷色香五月综合激情| 精品久久久久成人码免费动漫 | 久久AV高潮AV无码AV| 久久91精品国产91| 久久久亚洲欧洲日产国码二区|