地址: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. ytu 1052: 写一函数,将两个字符串连接(水题,指针练习)

    1052: 写一函数,将两个字符串连接 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 343  Solved: 210[Submit][Status][ ...

  2. 一些 JS页面的 调用方式init()

    //初始化.... var initAccManPage=function() { //初始化... var initChangeBtn = function(){ $("#btnChang ...

  3. Oracle索引相关

    oracle的索引分为5种:唯一索引,组合索引,反向键索引,位图索引,基于函数的索引. 创建索引的标准语法: CREATE INDEX 索引名 ON 表名 (列名) TABLESPACE 表空间名; ...

  4. java基础---->java中nio的使用(一)

    JDK 1.4 中引入的新输入输出 (NIO) 库在标准 Java 代码中提供了高速的.面向块的 I/O.今天我们就简单的学习一下nio的知识.我笑,便面如春花,定是能感动人的,任他是谁. nio的简 ...

  5. LeetCode-Lowest Common Ancestor of a Binary Tre

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  6. asfd

    $$\sum_{i=1}^n a_i=0$$$$f(x)=x^{x^x}$$

  7. JAVA编程你必须知道的那些英文单词

    第一章:  JDK(Java Development Kit) java开发工具包  JVM(Java Virtual Machine) java虚拟机  Javac  编译命令           ...

  8. JS中的call、apply、bind 用法解疑

    JS中的caller  arguments.callee  call  apply  bind方法 一.call()和apply()方法 1.方法定义 call方法: 语法:call([thisObj ...

  9. ehcache 的 配置文件: ehcache.xml的认识

    <ehcache> <!-- 指定一个目录:当 EHCache 把数据写到硬盘上时, 将把数据写到这个目录下. --> <diskStore path="d:\ ...

  10. window下cmd的宽度调整

    一直被cmd的宽度这么了好些年,刚才搜索了下,还真可以设置.标题栏右键属性,调整屏幕缓冲区宽度,只要足够长就不会换行了,然后调整窗口大小-宽度,不能超过屏幕缓冲区宽度,当小于屏幕缓冲区的时候,就会显示 ...