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 }
  • 相关阅读:
    如何在linux系统中设置静态ip地址
    spring 学习
    java 反射机制和invoke方法
    CentoS7装机
    eclipse 添加jar包的方式
    No-args constructor for class does not exist. Register an InstanceCreator with G
    freemarker页面如何获取绝对路径basePath
    MySQL备份还原
    MySQL用户授权与权限
    CentOS7修改SSH远程连接端口
  • 原文地址:https://www.cnblogs.com/Tree-dream/p/7442624.html
Copyright © 2011-2022 走看看