zoukankan      html  css  js  c++  java
  • poj 2185

    http://poj.org/problem?id=2185

    题意:有一个矩形的网,这个网是由一个一个的小的矩形构成的,问这个最小矩形的面积

    思路:找出每一行的所有的子字符串,这个子字符串可以循环构成这个字符串,然后统计相同的位置有多少个,最少的字符的统计的数量达到了字符串的个数的时候,这个就是最少的列的数目

    然后最少行就是对于每一行字符串当成一个字符进行求next就可以

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 char str[20050][200];
     5 int m,n;
     6 int num[20050];
     7 int next[20050];
     8 char tmp[20050];
     9 
    10 bool match(char *a,char *b)
    11 {
    12     int len = strlen(a);
    13     for(int i = 0,j = 0;i<n;i++,j++)
    14     {
    15         if(j==len)
    16             j = 0;
    17         if(a[j]!=b[i])
    18             return false;
    19     }
    20     return true;
    21 }
    22 
    23 void getnext()
    24 {
    25     next[0] = -1;
    26     int i = 0,j = -1;
    27     while(i<m)
    28     {
    29         if(j==-1||strcmp(str[i],str[j])==0)
    30             next[++i]=++j;
    31         else
    32             j = next[j];
    33     }
    34 }
    35 
    36 int main()
    37 {
    38     while(~scanf("%d%d",&m,&n))
    39     {
    40         for(int i = 0;i<m;i++)
    41             scanf("%s",str[i]);
    42         memset(num,0,sizeof(num));
    43         memset(next,0,sizeof(next));
    44 
    45 
    46 
    47         for(int i = 0;i<m;i++)
    48         {
    49             for(int j = 0;j<n;j++)
    50             {
    51                 tmp[j] = str[i][j];
    52                 tmp[j+1] = 0;
    53                 if(match(tmp,str[i]))
    54                     num[j]++;
    55             }
    56         }
    57         getnext();
    58         int t = n;
    59         for(int i = 0;i<n;i++)
    60             if(num[i]==m)
    61             {
    62                 t = i+1;
    63                 break;
    64             }
    65         printf("%d
    ",t*(m-next[m]));
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    python多线程多进程
    python单元测试unittest
    python学习笔记(一):python简介和入门
    今天的收获!!!
    Python django
    React router
    30分钟掌握ES6/ES2015核心内容
    webpack+React.js
    我喜欢的两个js类实现方式 现在再加上一个 极简主义法
    js实现的笛卡尔乘积-商品发布
  • 原文地址:https://www.cnblogs.com/Tree-dream/p/7442624.html
Copyright © 2011-2022 走看看