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

            poj2185 Milking Grid

            Milking Grid

            Time Limit: 3000MS Memory Limit: 65536K
            Total Submissions: 3879 Accepted: 1598

            Description

            Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently writing a book about feeding behavior in cows. He notices that if each cow is labeled with an uppercase letter indicating its breed, the two-dimensional pattern formed by his cows during milking sometimes seems to be made from smaller repeating rectangular patterns.

            Help FJ find the rectangular unit of smallest area that can be repetitively tiled to make up the entire milking grid. Note that the dimensions of the small rectangular unit do not necessarily need to divide evenly the dimensions of the entire milking grid, as indicated in the sample input below.

            Input

            * Line 1: Two space-separated integers: R and C

            * Lines 2..R+1: The grid that the cows form, with an uppercase letter denoting each cow's breed. Each of the R input lines has C characters with no space or other intervening character.

            Output

            * Line 1: The area of the smallest unit from which the grid is formed

            Sample Input

            2 5
            ABABA
            ABABA
            

            Sample Output

            2
            

            Hint

            The entire milking grid can be constructed from repetitions of the pattern 'AB'.

            Source

            USACO 2003 Fall

            字符串的好題
            咋一看摸不到頭緒,但是自習想會有一些想法
            可以求出每一行的覆蓋的,和每一列的覆蓋的
            然后再求最小公倍數之類的處理
            我們可以完善一下思路,看那個discuss里有個講的好的
            http://blog.sina.com.cn/s/blog_69c3f0410100tyjl.html
            鏈接到這了

            找出每行的重復子串長度的各種可能情況,然后每行都有的并且是最小長度作為寬width。
            第二步找最小重復子矩陣的高,這個思路和網上的差不多,取每行的寬為width的前綴作為一個單位,對這0到r-1個單位求出KMP的next函數,找出最小重復子序列的單位數作為高height,最終答案為width*height。

            代碼哎
            涉及了好多東西,
            kmp的next 的用法 請移步這里 http://blog.csdn.net/xiaoxiaoluo/article/details/7422912
            這里證明了 一個字符串的最小覆蓋子串是 len-next[len]
            然后求那個width也有些技巧
            代碼很短,但很精彩

            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 10005
            char s[maxn][80];
            int r,c;
            int p[maxn],f[80];
            char a[80];
            int main()
            {
                
            int i,j,x,y;
                scanf(
            "%d%d",&r,&c);
                memset(f,
            0,sizeof(f));
                
            for(i=0; i<r; i++)
                
            {
                    scanf(
            "%s",s[i]);
                    strcpy(a,s[i]);
                    
            for(j=c-1; j>0; j--)
                    
            {
                        a[j]
            ='\0';//changduwwei j
                        for(x=0,y=0; s[i][y]; x++,y++)
                        
            {
                            
            if(a[x]=='\0') x=0;//jieduan
                            if(a[x]!=s[i][y])break;//butong bushi chongfuzichuan
                        }

                        
            if(s[i][y]=='\0')f[j]++;//changduwei j keyi fugaiquanchuan
                    }

                }

                
            for(i=1; i<c; i++)
                    
            if(f[i]==r) break;//最短能覆蓋的公共長度
                x=i;
                
            //cout<<x<<endl;
                for(i=0; i<r; i++) s[i][x]='\0';
                p[
            0]=-1;//kmp求next的過程
                j=-1;
                
            for(i=1; i<r; i++)
                
            {
                    
            while((j!=-1)&&strcmp(s[j+1],s[i])) j=p[j];
                    
            if(strcmp(s[j+1],s[i])==0) j++;
                    p[i]
            =j;
                }

                
            //cout<<r-1-p[r-1]<<endl;
                printf("%d\n",(r-1-p[r-1])*x);
                
            return 0;
            }

            posted on 2012-07-18 22:17 jh818012 閱讀(146) 評論(0)  編輯 收藏 引用

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

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久综合日本熟妇| 精品久久一区二区三区| 国产精品久久久天天影视香蕉 | 99久久99久久精品国产片果冻| 亚洲国产一成久久精品国产成人综合 | 日韩一区二区久久久久久| 国产综合久久久久久鬼色| 久久精品无码一区二区三区| 精品久久久无码中文字幕| 午夜精品久久久久久影视riav| 熟妇人妻久久中文字幕| 草草久久久无码国产专区| 伊人久久大香线蕉AV色婷婷色| 99久久国产免费福利| 色天使久久综合网天天| 97久久精品午夜一区二区| 久久久久亚洲AV无码专区网站 | 午夜精品久久久内射近拍高清| 国产成人久久精品一区二区三区| 久久99精品久久久久久久不卡| 1000部精品久久久久久久久| 欧美国产成人久久精品| 99久久人妻无码精品系列蜜桃| 狠狠色丁香婷婷久久综合五月| 久久亚洲精品无码播放| 久久综合伊人77777麻豆| 色婷婷狠狠久久综合五月| 蜜桃麻豆WWW久久囤产精品| 久久久久久久精品妇女99| 狠狠色丁香久久婷婷综合| 国产美女久久久| 精品视频久久久久| 欧美黑人激情性久久| 波多野结衣中文字幕久久| 日韩va亚洲va欧美va久久| 亚洲国产欧洲综合997久久| 国产精品久久久久影院嫩草| 一级做a爰片久久毛片毛片| 久久ZYZ资源站无码中文动漫| 中文精品久久久久国产网址| 性色欲网站人妻丰满中文久久不卡|