首页 > 代码库 > hdu 2609 How many 最小表示法
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.
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‘).
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
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <string.h> 5 #include <set> 6 using namespace std; 7 set<string>ss; 8 void make(char a[],int x,int l) 9 {10 char b[150];11 int i;12 for(i=0; i<l; i++)13 b[i]=a[x+i>=l?x+i-l:x+i];14 b[i]=‘\0‘;15 ss.insert(b);16 }17 void moremin(char a[])18 {19 int len=strlen(a);20 int i,j,k,t;21 k=i=0;22 j=1;23 while(i<len&&j<len&&k<len)24 {25 int t=a[i+k>=len?i+k-len:i+k]-a[j+k>=len?j+k-len:j+k];26 if(!t)k++;27 else28 {29 if(t>0) i+=k+1;30 else j+=k+1;31 if(i==j)j++;32 k=0;33 }34 }35 make(a,(i>j?j:i),len);36 }37 int main()38 {39 int n;40 char a[150];41 while(~scanf("%d",&n))42 {43 ss.clear();44 while(n--)45 {46 scanf("%s",a);47 moremin(a);48 }49 cout<<ss.size()<<endl;50 }51 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。