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 ...
随机推荐
- hdu 1520(简单树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 思路:dp[u][0]表示不取u的最大价值,dp[u][1]表示取u的最大价值,于是有dp[u] ...
- jboss6.4 域模式自动部署
1.通过jenkins传递部署包到服务器,调用自动部署shell完成jboss6.4的域模式部署: 2.自动部署shell如下: 完成部署包重命名(从jenkins过来的包可能没有改名:). 调用jb ...
- 编程之美 set 18 拈两堆石子游戏(3)
题目 假设有两堆石头, 有两个玩家按照如下规则轮流取石头 每个人每次可以从两堆石头中取出数量相等的石头, 或者仅从一堆石头中取出任意数量的石头 最后把剩下的石头依次拿光的人取胜 首先取石头的人能否赢得 ...
- Python tushare 初步了解
一.安装 1.Python 2.numpy 3.pandas 4.lxml 5.............. n.tushare 二.初步测试
- Linux命令之乐--test
官方文档: help test File operators: -a FILE True if file exists. -b FILE True if file is block special. ...
- 第十一篇:Linux中权限的再讨论( 下 )
前言 上篇随笔讲述了Linux中权限的大致实现机制以及目录权限的相关规则.本文将讲解Linux中的三种特殊权限:SUID,SGID,Sticky权限. 看完这两篇文章,你一定会对Linux的权限有个更 ...
- springboot tomcat的使用
使用自带的tomcat 以java 项目启动: 默认端口号为8080 1.必须导入此包 2.有启动类
- win上gulp配置
主线: 安装nodejs -> 全局安装gulp -> 项目安装gulp以及gulp插件 -> 配置gulpfile.js -> 运行任务 1,安装node.js 1.1.说明 ...
- [Gradle] 给已存在的 task 添加依赖
需求:在编译宿主 APP 之前先编译两个插件 SamplePlugin1 和 SamplePlugin2 tasks.whenTaskAdded { task -> if (task.name ...
- [LeetCode] 7.Reverse Integer - Swift
Reverse digits of an integer. Example1: x = , return Example2: x = -, return - 题目意思:对一个整型进行反转 实现代码: ...