地址:http://acm.hdu.edu.cn/showproblem.php?pid=2609

题目:

How many

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2625    Accepted Submission(s): 1135

Problem Description
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me
How many kinds of necklaces total have.(if two necklaces can equal by rotating ,we say the two necklaces are some).
For example 0110 express a necklace, you can rotate it. 0110 -> 1100 -> 1001 -> 0011->0110.
 
Input
The input contains multiple test cases.
Each test case include: first one integers n. (2<=n<=10000)
Next n lines follow. Each line has a equal length character string. (string only include '0','1').
 
Output
For each test case output a integer , how many different necklaces.
 
Sample Input
4
0110
1100
1001
0011
4
1010
0101
1000
0001
 
Sample Output
1
2
 
Author
yifenfei
 
Source
 
Recommend
yifenfei
 
思路:最大最小表示法+set
 #include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
const double eps=1e-;
const int K=1e6+;
const int mod=1e9+; char sb[];
//ff为真表示最小,为假表示最大
//S串应该为原串复制两次后的字符串
int mx_mi_express(char *S,bool ff,int len)
{
int i=,j=,k;
while(i<len&&j<len)
{
k=;
while(k<len&&S[i+k]==S[j+k]) k++;
if(k==len) return i<=j?i:j;
if((ff&&S[i+k]>S[j+k]) || (!ff&&S[i+k]<S[j+k]))
{
if(i+k+>j) i=i+k+;
else i=j+;
}
else if((ff&&S[i+k]<S[j+k]) || (!ff&&S[i+k]>S[j+k]))
{
if(j+k+>i) j=j+k+;
else j=i+;
}
}
return i<=j?i:j;
}
string tmp;
set<string>st;
int main(void)
{
int t,n,len;
while(scanf("%d",&n)==&&n)
{
st.clear(),tmp.clear(),len=;
for(int i=,be;i<=n;i++)
{
scanf("%s",sb);
if(!len)
{
len=strlen(sb);
for(int j=;j<len;j++)
tmp+='';
}
for(int j=;j<len;j++)
sb[j+len]=sb[j];
be=mx_mi_express(sb,,len);
for(int j=;j<len;j++)
tmp[j]=sb[j+be];
st.insert(tmp);
}
printf("%d\n",st.size());
}
return ;
}

hdu2609 How many的更多相关文章

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

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

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

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

  3. hdu2609最小表示法

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

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

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

  5. hdu2609 最小表示法

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

  6. hdu2609(最小表示法)

    题意:有n个环形字符串,一个环形字符串移动会形成不能的字符串,我们把它们看作同一串字符串,求有多少个不同的字符串....... 思路:用最小表示发将一个环形串的最小字典序找出来,然后让这个环形串按照这 ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

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

  8. hdu-2609 How many---最小表示法模板+set判重

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2609 题目大意: 有n个有01组成的字符串,每个字符串都代表一个项链,那么该字符串就是一个环状的结构 ...

  9. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. jQuery实现淡入淡出二级下拉导航菜单的方法

    本文实例讲述了jQuery实现淡入淡出二级下拉导航菜单的方法.分享给大家供大家参考.具体如下: 这是一款基于jQuery实现的导航菜单,淡入淡出二级的菜单导航,很经常见到的效果,这里使用的是jquer ...

  2. 10条建议帮助你创建更好的jQuery插件

    本文总结了帮助你创建更好jQuery插件的10条建议.分享给大家供大家参考.具体说明如下: 在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就 ...

  3. iOS开发之--NSData与UIImage之间的转换

    //NSData转换为UIImage NSData *imageData = [NSData dataWithContentsOfFile: imagePath]; UIImage *image = ...

  4. shell脚本学习总结12--系统信号

    信号是Linux系统中一种进程通信机制.我们可以使用特定的信号来中断进程.每一种信号都同一个整数值相关联. kill命令可用来想进程发送信号,而trap命令用来处理所接收的信号. kill 列出所有可 ...

  5. CSS解决图片缩小不变形

    我会在图片上加: <img style="max-width:80px;max-height:80px;"> 限制其最大宽度和高度

  6. 前端性能优化-减少http请求,dns预解析,减少repaint和reflow

    前端性能优化方法: 一 . 减少http请求 (1)通过合并图片,减少请求,俗称css sprites(css精灵)css sprites (2)lazyload懒加载,在需要的时候再加载 1.定义: ...

  7. 解决<pre>标签里的文本换行(兼容IE, FF和Opera等)

      我们都知道<pre> 标签可定义预格式化的文本,一个常见应用就是用来表示计算机的源代码.被包围在 pre 元素中的文本通常会保留空格和换行符,但不幸的是,当你在<pre>标 ...

  8. CH5102 Mobile Service【线性dp】

    5102 Mobile Service 0x50「动态规划」例题 描述 一个公司有三个移动服务员,最初分别在位置1,2,3处.如果某个位置(用一个整数表示)有一个请求,那么公司必须指派某名员工赶到那个 ...

  9. ROS 笔记

    ros的编程范式 - ros认为,linux平台下,机器人的软件由一个个小程序组成,这些小程序称为node,每个小程序负责一部分功能 - ros实现的框架就是,小程序的并发执行+相互通信,程序(进程) ...

  10. DEV中gridview常用属性

    1.隐藏最上面的GroupPanel: gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值: sValue=Table.Rows[g ...