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 ...
随机推荐
- 【Openwrt】刷
设定你的电脑ip 为192.168.1.100 网线一头连接lan口,另外一头连接电脑.WAN口不能插线. 按住路由器的qss 键,开启路由器的电,灯灭掉,等6秒左右灯会再次闪几下就松开,用googl ...
- React-Native 样式指南
https://github.com/doyoe/react-native-stylesheet-guide
- HDU 1058 Humble Numbers (动规+寻找丑数问题)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- THINKPHP5获取设置缓存的例子
在THINKPHP5中 缓存的配置放在了config.php文件中 代码如下 如何设置缓存? 可以使用静态方法 Cache::set('key',$value,3600);//存储缓存 Cache:: ...
- 【IIS】模块 DLL C:\Windows\System32\inetsrv\authcert.dll 未能加载。返回的数据为错误信息。
解决方案,check IIS --Client Certificate Mapping Authentication installed?
- node 同异步处理
同步:序列执行,需等待 异步:非序列执行,无需等待 node同步处理:读取->输出->完毕(队列式执行) node异步处理:读取->完毕(回调输出)(后两步同时进行,谁先到谁先输出) ...
- java发展历程、常用dos命令与jDK工具使用
Java菜鸟学习之旅 1.勤敲代码 2.必须将课堂上讲的内容学到位 2.1 学到会用 2.2 在学会之前不要自作主张 2.3 当天课程当天完成 3.能说会道 3.1 善于表达 3.2 学会的都能讲 4 ...
- CH5301 石子合并【区间dp】
5301 石子合并 0x50「动态规划」例题 描述 设有N堆沙子排成一排,其编号为1,2,3,…,N(N<=300).每堆沙子有一定的数量,可以用一个整数来描述,现在要将这N堆沙子合并成为一堆, ...
- R语言中的MySQL操作
R语言中,针对MySQL数据库的操作执行其实也有很多中方式.本人觉得,熟练掌握一种便可,下面主要就个人的学习使用情况,总结其中一种情况-----使用RMySQL操作数据库. 1.下载DBI和RMySQ ...
- wf-删除所选
w框架-结合用户的不同点击路径,提交正确的id集合. <table class="table"> <tr> <td></td> &l ...