hdu2609 How many
地址: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
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.
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').
0110
1100
1001
0011
4
1010
0101
1000
0001
2
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <set>
- #include <string>
- using namespace std;
- #define MP make_pair
- #define PB push_back
- typedef long long LL;
- const double eps=1e-;
- const int K=1e6+;
- const int mod=1e9+;
- char sb[];
- //ff为真表示最小,为假表示最大
- //S串应该为原串复制两次后的字符串
- int mx_mi_express(char *S,bool ff,int len)
- {
- int i=,j=,k;
- while(i<len&&j<len)
- {
- k=;
- while(k<len&&S[i+k]==S[j+k]) k++;
- if(k==len) return i<=j?i:j;
- if((ff&&S[i+k]>S[j+k]) || (!ff&&S[i+k]<S[j+k]))
- {
- if(i+k+>j) i=i+k+;
- else i=j+;
- }
- else if((ff&&S[i+k]<S[j+k]) || (!ff&&S[i+k]>S[j+k]))
- {
- if(j+k+>i) j=j+k+;
- else j=i+;
- }
- }
- return i<=j?i:j;
- }
- string tmp;
- set<string>st;
- int main(void)
- {
- int t,n,len;
- while(scanf("%d",&n)==&&n)
- {
- st.clear(),tmp.clear(),len=;
- for(int i=,be;i<=n;i++)
- {
- scanf("%s",sb);
- if(!len)
- {
- len=strlen(sb);
- for(int j=;j<len;j++)
- tmp+='';
- }
- for(int j=;j<len;j++)
- sb[j+len]=sb[j];
- be=mx_mi_express(sb,,len);
- for(int j=;j<len;j++)
- tmp[j]=sb[j+be];
- st.insert(tmp);
- }
- printf("%d\n",st.size());
- }
- return ;
- }
hdu2609 How many的更多相关文章
- HDU2609 How many —— 最小表示法
题目链接:https://vjudge.net/problem/HDU-2609 How many Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- hdu2609 How many【最小表示法】【Hash】
How many Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu2609最小表示法
#include <iostream> #include <algorithm> #include <string.h> #include <cstdio&g ...
- hdu2609 How many 字典树+最小表示法
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell meHow many ...
- hdu2609 最小表示法
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- hdu2609(最小表示法)
题意:有n个环形字符串,一个环形字符串移动会形成不能的字符串,我们把它们看作同一串字符串,求有多少个不同的字符串....... 思路:用最小表示发将一个环形串的最小字典序找出来,然后让这个环形串按照这 ...
- 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 ...
- hdu-2609 How many---最小表示法模板+set判重
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2609 题目大意: 有n个有01组成的字符串,每个字符串都代表一个项链,那么该字符串就是一个环状的结构 ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
随机推荐
- 用户控件(ASCX)向网页(ASPX)传值使用反射实现
用户控件向网页传递值,方法非常之多,此博文尝试使用反射来实现.在站点中,建一个网页以及一个用户控件. 网页切换至设计模式,拉用户控件至网页上. Default.aspx: <%@ Page La ...
- 如何用ChemFinder制作子表单
通过使用ChemFinder这一插件,用户可以建立自己的ChemFinder数据库,数据库是由表单集合而成,所以建立数据库的前提是要制作表单.在之前的教程中已经介绍了制作表单的方法,本节ChemDra ...
- xc_domain_save.c
/****************************************************************************** * xc_linux_save.c * ...
- Android 蓝牙学习
Android 蓝牙学习 学习缘由 上个礼拜公司要开发个简单的五子棋游戏!其中一个需求就是支持蓝牙对战!所以苦逼的我学习蓝牙方面的知识了! 简介 Bluetooth是目前使用最广泛的无线通讯协议,近距 ...
- oracle的存储过程如何返回结果集
CREATE OR REPLACE PACKAGE pkg_test AS TYPE myrctype IS REF CURSOR; PROCEDURE get (p_id NUM ...
- LeetCode-Add and Search Word
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- Excel单元格格式设置
工作中遇到一些小问题: 例如办公自动化里的如何设置单元格格式 此格式分为两种:一种是样式上的格式 比如边框 行距字体等 第二种为数据格式: 比如每次我输入1000的话自动变红或者加粗字体 office ...
- Freebsd下用pureftpd配置FTP服务器
pureftpd安装配置简明说明 1.下载 http://sourceforge.net/projects/pureftpd/ 最新版本是pure-ftpd-1.0.16a.tar.bz2 BSD自 ...
- Delphi编写下载程序:UrlDownloadToFile的进度提示
urlmon.dll中有一个用于下载的API,MSDN中的定义如下: HRESULT URLDownloadToFile( LPUNKNOWN pCaller, L ...
- 【Python算法】递归与递归式
该树结构显示了从1(根节点)到n(n个叶节点)的整个倍增过程.节点下的标签表示从n减半到1的过程. 当我们处理递归的时候,这些级数代表了问题实例的数量以及对一系列递归调用来说处理的相关工作量. 当我们 ...