地址: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. hdu 1181:变形课(搜索水题)

    变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submis ...

  2. windows 2003 发布遇到问题---分析器错误消息: 未能加载类型“YWPT.MvcApplication”。

    问题如下: “/”应用程序中的服务器错误. ------------------------------------------------------------------------------ ...

  3. 【BZOJ1217】[HNOI2003]消防局的设立 树形DP

    [BZOJ1217][HNOI2003]消防局的设立 Description 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地, ...

  4. 【BZOJ3436】小K的农场 差分约束

    [BZOJ3436]小K的农场 Description 背景 小K是个特么喜欢玩MC的孩纸... 描述 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了, ...

  5. 关东升的《从零开始学Swift》3月9日已经上架

    大家一直期盼的<从零开始学Swift>于3月9日已经上架,它是关东升老师历时8个月的呕心沥血所编著,全书600多页,此本书基于Swift 2.x,通过大量案例全面介绍苹果平台的应用开发.全 ...

  6. 初级Java面试题 - JavaSE篇

    p{font-size:18px;} li{font-size:18px;} 加入我的QQ群(701974765) 获取更多好用又好玩的软件,还有不定期发放的福利呦(- ̄▽ ̄)- Java基本数据类型 ...

  7. 170413、怎么精确理解leader布置的任务(技术外的话)

    [缘起] 和一个同学交代了一个很重要的事情,结果执行的结果并不是自己想要的,微微生气之余,简单的聊聊“如何精确的理解leader布置的任务”. [员工角度的潜在困惑] 1)leader讲了很多,脑子记 ...

  8. echart使用总结

    以下参数都是写在option配置对象内,没有提及的配置参数欢迎查阅读echart参考手册. 一. 修改主标题和副标题 title : { text: '未来一周气温变化',//写入主标题 subtex ...

  9. 《Django By Example》第十二章(终章) 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第十二章,全书最后一章,终于到这章 ...

  10. HDU_5532_Almost Sorted Array

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...