题意:有n个环形字符串,一个环形字符串移动会形成不能的字符串,我们把它们看作同一串字符串,求有多少个不同的字符串.......

思路:用最小表示发将一个环形串的最小字典序找出来,然后让这个环形串按照这个顺序来组成一个新的串,其他串都这样处理,然后去重,输出结果就是了.......

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[10005][105];
struct node
{
char ch[105];
}t[10005];
int cmp(const node a,const node b)
{
if(strcmp(a.ch,b.ch)<0)
return 1;
else
return 0;
}
int work(int m,char str[])
{
int i,j,l;
i=0; j=1;
while(i<m && j<m)
{
for(l=0;l<m;l++)
if(str[(i+l)%m]!=str[(j+l)%m]) break;
if(l>m) break;
if(str[(i+l)%m] > str[(j+l)%m])
i=i+l+1;
else
j=j+l+1;
if(i==j) j=i+1;
}
if(i<j) return i;
return j;
}
int main()
{
int n;
while(scanf("%d",&n)>0)
{
for(int i=1;i<=n;i++)
scanf("%s",s[i]);
for(int i=1;i<=n;i++)
{
int len=strlen(s[i]);
int cnt=work(len,s[i]);
strcpy(t[i].ch,s[i]+cnt);
s[i][cnt]='\0';
strcpy(t[i].ch+len-cnt,s[i]);
}
sort(t+1,t+1+n,cmp);
int sum=1;
for(int i=2;i<=n;i++)
{
if(strcmp(t[i-1].ch,t[i].ch)!=0)
sum++;
}
printf("%d\n",sum);
}
return 0;
}

hdu2609(最小表示法)的更多相关文章

  1. hdu2609 最小表示法

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. hdu2609最小表示法

    #include <iostream> #include <algorithm> #include <string.h> #include <cstdio&g ...

  3. HDU2609 How many —— 最小表示法

    题目链接:https://vjudge.net/problem/HDU-2609 How many Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  4. hdu2609 How many【最小表示法】【Hash】

    How many Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. hdu2609 How many 字典树+最小表示法

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell meHow many ...

  6. HDU 4162 Shape Number (最小表示法)

    题意:给你一串n个数,求出循环来看一阶差的最小字典序:数字串看成一个顺时针的环,从某一点开始顺时针循环整个环,保证字典序最小就是答案 例如给你 2 1 3 就会得到(1-2+8 注意题意负数需要加8) ...

  7. POJ 1635 树的最小表示法/HASH

    题目链接:http://poj.org/problem?id=1635 题意:给定两个由01组成的串,0代表远离根,1代表接近根.相当于每个串对应一个有根的树.然后让你判断2个串构成的树是否是同构的. ...

  8. HDU 2609 最小表示法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...

  9. HDU 4162 最小表示法

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162 题意:给定一个只有0-7数字组成的串.现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字 ...

  10. POJ 1509 最小表示法

    题目链接:http://poj.org/problem?id=1509 题意:给定一个字符串,求一个起点使字符串从该起点起的字符串字典序最小[题目的字符串起点从1开始] 思路:最小表示法模板题 #de ...

随机推荐

  1. 让一个表单以post的方式在window.open的窗口中打开

    我们都知道window.open(url)是最基本的用法,很多人都在url里用?xx=11&yy=22的方式拼接参数,但是其实我们不愿意让使用者看到后面的参数,这时我们可以如下方法 JS如下: ...

  2. 23、List集合

    1.List List接口是Collection的子接口,用于定义线性表数据结构.List是可重复集 2.List自身定义的方法 List处理继承Collection方法外,自己还定义了其它方法,例如 ...

  3. 微信小程序条码、二维码生成模块

    代码地址如下:http://www.demodashi.com/demo/13994.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

  4. BroadcastReceiver之实现锁屏、解锁样例

    好久没有写android的小样例了,因为前几天写了一篇关于Intent.Action的文章(http://blog.csdn.net/ljphhj/article/details/38796739). ...

  5. POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56150   Accepted: 19398 Desc ...

  6. Integer 内部实现

    public static void main(String[] args) { Integer in1 = 128; Integer in2 = 128; System.out.println(in ...

  7. iOS AppIcon尺寸和上传ITunes构建版本尺寸和iPhone屏幕尺寸

    避免忘记. 记录一下 App Icon: 29X2940X4058X5876X7687X8780X80120X120152X152167X167180X180 ITunes构建版本: 1242 x 2 ...

  8. HDUOJ-----2824The Euler function

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. xp 如何打开(进行)远程桌面连接

    http://apps.hi.baidu.com/share/detail/31102654http://help.360.cn/5030804/40072526.htmlhttp://hi.baid ...

  10. java JAXB + STAX(是一种针对XML的流式拉分析API)读取xml

    JDK1.5需要添加jar包,1.6以后就不需要了<dependency> <groupId>stax</groupId> <artifactId>st ...