hdu 2609 How many 最小表示法

How many

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

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
 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
set<string>ss;
void make(char a[],int x,int l)
{
char b[];
int i;
for(i=; i<l; i++)
b[i]=a[x+i>=l?x+i-l:x+i];
b[i]='\0';
ss.insert(b);
}
void moremin(char a[])
{
int len=strlen(a);
int i,j,k,t;
k=i=;
j=;
while(i<len&&j<len&&k<len)
{
int t=a[i+k>=len?i+k-len:i+k]-a[j+k>=len?j+k-len:j+k];
if(!t)k++;
else
{
if(t>) i+=k+;
else j+=k+;
if(i==j)j++;
k=;
}
}
make(a,(i>j?j:i),len);
}
int main()
{
int n;
char a[];
while(~scanf("%d",&n))
{
ss.clear();
while(n--)
{
scanf("%s",a);
moremin(a);
}
cout<<ss.size()<<endl;
}
}
 
上一篇:1.Linux系统安装


下一篇:如何将一个IP地址移出PBL,不然,国内邮件服务器不能正常发送国外邮件哟。