hdu 2609 How many
来源:互联网 发布:奥尼尔新秀赛季数据 编辑:程序博客网 时间:2024/06/07 03:26
点击打开链接
How many
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3251 Accepted Submission(s): 1446
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
4011011001001001141010010110000001
Sample Output
12
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>using namespace std;char str[10005][105];char st[10005][105];int mi_ma(char *s,int len){ int i = 0, j = 1, k = 0; while(i < len && j < len && k < len) { int t = s[(j + k) % len] - s[(i + k) % len]; if(t == 0) k++; else { if(t > 0) j += k + 1; else i += k + 1; if(i == j) j++; k = 0; } } return min(i, j);}int main(){ int n; while(cin >> n) { for(int i = 0; i < n; i++) { scanf("%s", str[i]); int len=strlen(str[i]); int t = mi_ma(str[i],len); int j=0,k; for(k=t;k<len;k++) st[i][j++]=str[i][k]; for(k=0;k<t;k++) st[i][j++]=str[i][k]; st[i][j]='\0'; } set<string>ff; for(int i=0;i<n;i++) ff.insert(st[i]); cout<<ff.size()<<endl; } return 0;}
参考博客
http://blog.csdn.net/piaocoder/article/details/48447193
阅读全文
0 0
- hdu 2609 How Many
- hdu 2609 How many
- hdu 2609 How many
- HDU 2609 How Many
- HDU 2609 How many
- hdu 2609 how many
- HDU 2609 How many
- HDU 2609How many
- hdu 2609 How many
- hdu 2609 How many(最小表示法)
- [最小表示法] hdu 2609 How many
- HDU——2609 How many
- [最小表示法] HDU 2609 How many
- HDU - 2609 How many(最小表示法)
- HDU 2609 How many(最小表示法)
- HDU-2609 How many (最小表示法)
- HDU 2609 How many [最小表示法]
- hdu How Many Tables
- 外观模式
- ABAQUS更改默认工作目录
- 机房收费系统——可行性研究报告
- 多台电脑磁盘(文件共享 磁盘共享)局域网共享
- usaco Healthy Holsteins
- hdu 2609 How many
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776F. Sherlock's bet to Moriarty(待翻译)
- 基于GSoap/protobuf的服务性能优化
- XML头声明和standalone的解释
- iOS开发代码规范
- 编译?
- java类加载
- c++日志输出
- java 虚拟机