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. 

InputThe 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'). 
OutputFor 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
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 10002
/*
题目相当于求所有字符串中
能通过相互循环位移得到的字符串数目
对每个字符串求最小表示法,然后加入到set中
*/
string str;
set<string> S;
int GetMin(string s,int len)
{
int i=,j=,k=;
while(i<len&&j<len&&k<len)
{
if(s[(i+k)%len]==s[(j+k)%len])
k++;
else if(s[(i+k)%len]>s[(j+k)%len])
{
i = i+k+;
k = ;
}
else
{
j = j+k+;
k = ;
}
if(i==j)
j++;
}
return min(i,j);
}
int main()
{
int n;
string tmp;
tmp.reserve();
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
{
tmp.clear();
cin>>str;
int pos = GetMin(str,str.size()),L = str.size();
for(int j=pos,cnt=;cnt<L;j=(j+)%L,cnt++)
{
tmp.push_back(str[j]);
}
S.insert(tmp);
}
cout<<S.size()<<endl;
S.clear();
}
}

最新文章

  1. de4dot3.14更新文件打包下载
  2. mysql的故事
  3. mysql在ubuntu下的安装
  4. Linux常用压缩和解压命令
  5. Wikipedia : OIT history
  6. Debug的F5~F8用法
  7. MSP430F149学习之路——按键与LED
  8. Ubuntu重启网络/etc/init.d/networking restart报错
  9. Windows Forms(二)
  10. boost 的函数式编程库 Phoenix入门学习
  11. SpringMVC第一天(其他)
  12. C# 6 与 .NET Core 1.0 高级编程 - 40 ASP.NET Core(上)
  13. 数值函数ROUND(四舍五入),TRUNC(不四舍五入),MOD
  14. RobotFramework自动化测试框架的基础关键字(二)
  15. 为label或者textView添加placeHolder
  16. java跨域
  17. 对于长沙互联网发展,一个外来两年Java程序员的所见所感所愿
  18. java的Map遍历
  19. MFC连接MySQL
  20. 预加载与智能预加载(iOS)

热门文章

  1. eclipse.ini启动参数配置的解析及方法
  2. jmeter中beanshell断言的使用
  3. ACM_二维数组的查找
  4. java 重载父类报错 Remove &#39;@override&#39; annotation解决办法
  5. 我正在学英语是用learning english还是用studying english?
  6. win32动态库
  7. JS高级——原型链
  8. javascript之console篇
  9. vim之&lt;F12&gt; 一键生成tags的一些小优化
  10. atom 插件安装【转载】