[转]浅析“最小表示法”思想在字符串循环同构问题中的应用-HDU2609
来源:互联网 发布:java 9 发布 编辑:程序博客网 时间:2024/05/29 19:23
ACM偶尔会出现最小表示法的题目,下面是一些文档可以帮助理解。
下载地址
How many
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1117 Accepted Submission(s): 444
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
Author
yifenfei
Source
奋斗的年代
Recommend
yifenfei | We have carefully selected several similar problems for you: 2612 2572 1325 2610 1686
解释:见上面的pdf。Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor97690422013-12-06 16:16:07Accepted2609109MS2032K866 BC++
//第一次用最小表示法#include<iostream>#include<set>#include<string>#include<math.h>using namespace std;int GetMin(const string& src){int i=0,j=1,k=0,len=src.size(),pos;while (i < len && j < len && k < len){pos = src[(i+k)%len]-src[(j+k)%len];if( pos == 0 )++k;else{if( pos > 0 )i = i + k + 1;elsej = j + k + 1;if( i == j )++j;k = 0;}}return i < j ? i : j;}int main(){int T,pos,diff;string src,strTemp;set<string> Set;while(cin >> T){Set.clear();diff = 0;while( T-- ){cin >> strTemp;pos = GetMin(strTemp);src.assign(strTemp,pos,strTemp.size()-pos);if( pos )src.append(strTemp,0,pos);if( Set.count(src) == 0 ){++diff;Set.insert(src);}}cout << diff << endl;}return 0;}
- [转]浅析“最小表示法”思想在字符串循环同构问题中的应用-HDU2609
- 最小表示法 字符串循环同构问题
- 【字符串循环同构的最小表示法】
- 字符串循环同构的最小表示法(转)
- hdu2609 字符串的最小表示法模版
- HDU2609(字符串的最小表示法)
- 【理解字符串循环同构的最小表示法】
- 理解字符串循环同构的最小表示法
- 【理解字符串循环同构的最小表示法】
- 【理解字符串循环同构的最小表示法】
- 【理解字符串循环同构的最小表示法】
- 字符串循环同构——最小表示法の板子
- 理解字符串循环同构的最小/最大表示法+模板
- hdu2609(最小表示法)
- hdu2609(最小表示法+set)
- hdu2609-字符串最小表示法|模拟|二分+lcp-How many
- HDU2609 How many(字符串的最小表示法)
- 【字符串】【最小表示法】Vijos P1683 有根树的同构问题
- SLP 系列第 1 部分:基本介绍和对比分析
- 自定义ViewFlipper实现带索引效果的自动播放广告栏
- 感應은 乖違中의 相交
- 分布式设计与开发(二)------几种必须了解的分布式算法
- 你偷走了我的心
- [转]浅析“最小表示法”思想在字符串循环同构问题中的应用-HDU2609
- C++ 动态子类化 很神奇的code
- 三索과 三極
- SDL Image介绍
- 类装载器DexClassLoader (android内核剖析)
- 對待組織과 三才運行
- LP 系列第 2 部分:协议的扩展与改进
- 使用kprobes查看内核内部信息
- 社會의 新陳代謝