地址: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
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <set>
  5. #include <string>
  6. using namespace std;
  7.  
  8. #define MP make_pair
  9. #define PB push_back
  10. typedef long long LL;
  11. const double eps=1e-;
  12. const int K=1e6+;
  13. const int mod=1e9+;
  14.  
  15. char sb[];
  16. //ff为真表示最小,为假表示最大
  17. //S串应该为原串复制两次后的字符串
  18. int mx_mi_express(char *S,bool ff,int len)
  19. {
  20. int i=,j=,k;
  21. while(i<len&&j<len)
  22. {
  23. k=;
  24. while(k<len&&S[i+k]==S[j+k]) k++;
  25. if(k==len) return i<=j?i:j;
  26. if((ff&&S[i+k]>S[j+k]) || (!ff&&S[i+k]<S[j+k]))
  27. {
  28. if(i+k+>j) i=i+k+;
  29. else i=j+;
  30. }
  31. else if((ff&&S[i+k]<S[j+k]) || (!ff&&S[i+k]>S[j+k]))
  32. {
  33. if(j+k+>i) j=j+k+;
  34. else j=i+;
  35. }
  36. }
  37. return i<=j?i:j;
  38. }
  39. string tmp;
  40. set<string>st;
  41. int main(void)
  42. {
  43. int t,n,len;
  44. while(scanf("%d",&n)==&&n)
  45. {
  46. st.clear(),tmp.clear(),len=;
  47. for(int i=,be;i<=n;i++)
  48. {
  49. scanf("%s",sb);
  50. if(!len)
  51. {
  52. len=strlen(sb);
  53. for(int j=;j<len;j++)
  54. tmp+='';
  55. }
  56. for(int j=;j<len;j++)
  57. sb[j+len]=sb[j];
  58. be=mx_mi_express(sb,,len);
  59. for(int j=;j<len;j++)
  60. tmp[j]=sb[j+be];
  61. st.insert(tmp);
  62. }
  63. printf("%d\n",st.size());
  64. }
  65. return ;
  66. }

hdu2609 How many的更多相关文章

  1. HDU2609 How many —— 最小表示法

    题目链接:https://vjudge.net/problem/HDU-2609 How many Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  2. hdu2609 How many【最小表示法】【Hash】

    How many Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. hdu2609最小表示法

    #include <iostream> #include <algorithm> #include <string.h> #include <cstdio&g ...

  4. hdu2609 How many 字典树+最小表示法

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell meHow many ...

  5. hdu2609 最小表示法

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  6. hdu2609(最小表示法)

    题意:有n个环形字符串,一个环形字符串移动会形成不能的字符串,我们把它们看作同一串字符串,求有多少个不同的字符串....... 思路:用最小表示发将一个环形串的最小字典序找出来,然后让这个环形串按照这 ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  8. hdu-2609 How many---最小表示法模板+set判重

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2609 题目大意: 有n个有01组成的字符串,每个字符串都代表一个项链,那么该字符串就是一个环状的结构 ...

  9. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. 用户控件(ASCX)向网页(ASPX)传值使用反射实现

    用户控件向网页传递值,方法非常之多,此博文尝试使用反射来实现.在站点中,建一个网页以及一个用户控件. 网页切换至设计模式,拉用户控件至网页上. Default.aspx: <%@ Page La ...

  2. 如何用ChemFinder制作子表单

    通过使用ChemFinder这一插件,用户可以建立自己的ChemFinder数据库,数据库是由表单集合而成,所以建立数据库的前提是要制作表单.在之前的教程中已经介绍了制作表单的方法,本节ChemDra ...

  3. xc_domain_save.c

    /****************************************************************************** * xc_linux_save.c * ...

  4. Android 蓝牙学习

    Android 蓝牙学习 学习缘由 上个礼拜公司要开发个简单的五子棋游戏!其中一个需求就是支持蓝牙对战!所以苦逼的我学习蓝牙方面的知识了! 简介 Bluetooth是目前使用最广泛的无线通讯协议,近距 ...

  5. oracle的存储过程如何返回结果集

    CREATE OR REPLACE PACKAGE pkg_test AS     TYPE myrctype IS REF CURSOR;       PROCEDURE get (p_id NUM ...

  6. LeetCode-Add and Search Word

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  7. Excel单元格格式设置

    工作中遇到一些小问题: 例如办公自动化里的如何设置单元格格式 此格式分为两种:一种是样式上的格式 比如边框 行距字体等 第二种为数据格式: 比如每次我输入1000的话自动变红或者加粗字体 office ...

  8. Freebsd下用pureftpd配置FTP服务器

    pureftpd安装配置简明说明 1.下载  http://sourceforge.net/projects/pureftpd/ 最新版本是pure-ftpd-1.0.16a.tar.bz2 BSD自 ...

  9. Delphi编写下载程序:UrlDownloadToFile的进度提示

    urlmon.dll中有一个用于下载的API,MSDN中的定义如下: HRESULT URLDownloadToFile(             LPUNKNOWN pCaller,       L ...

  10. 【Python算法】递归与递归式

    该树结构显示了从1(根节点)到n(n个叶节点)的整个倍增过程.节点下的标签表示从n减半到1的过程. 当我们处理递归的时候,这些级数代表了问题实例的数量以及对一系列递归调用来说处理的相关工作量. 当我们 ...