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\n",t*(m-next[m]));
66     }
67     return 0;
68 }

 

转载于:https://www.cnblogs.com/Tree-dream/p/7442624.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值