地址: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 ;
}

最新文章

  1. 【Bugly干货分享】一起用 HTML5 Canvas 做一个简单又骚气的粒子引擎
  2. JavaScript中JSON的处理心得
  3. Mac 安装 home Brew以及 XCTool的过程记录
  4. EntityFramework4.1开发
  5. MSCRM 2015 新功能(一)
  6. JS表单学习笔记(思维导图)
  7. 【windows socket+TCPserverclient】
  8. ID卡学习笔记
  9. LINUX ON AZURE 安全建议(全)
  10. C#压缩文件夹坑~
  11. SpringMVC的入门示例---基于注解的配置
  12. Oracle树形查询
  13. java反射笔记
  14. PHP生成二维码并上传到七牛云
  15. linux git:fatal: HTTP request failed
  16. 基于session做的权限控制
  17. 一步一步来熟悉Akka.Net(一)
  18. tensorflow中使用Batch Normalization
  19. Python入门之用Python统计代码行
  20. 查询_修改SQL Server 2005中数据库文件存放路径

热门文章

  1. MySQL Error: PROCEDURE xmdk.query_all_plan can&#39;t return a result set in the given context
  2. WinFrom 第三方控件 TeleRik控件
  3. A mail sent to Google chromium.org Groups for Help
  4. jQuery------$.each()遍历类方法
  5. C语言数组元素的查询
  6. SQL ALTER TABLE 命令
  7. codevs 5965 [SDOI2017]新生舞会
  8. 【BZOJ3585/3339】mex 莫队算法+分块
  9. Linux下查看nginx的安装路径
  10. Action请求流程分析