HDU2609 How many(字符串的最小表示法)
来源:互联网 发布:java elasticsearch 编辑:程序博客网 时间:2024/05/28 17:08
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
4011011001001001141010010110000001
Sample Output
12
思路
给你n组字符串,每一个字符串可以自由的左移和右移,问一共有多少种字符串,我们可以用字符串的最小表示法把每一个字符串都表示一下,然后插入set中,返回元素数量就是要求的答案
代码
#include<cstdio>#include<cstring>#include<string>#include<set>#include<iostream>#include<stack>#include<queue>#include<vector>#include<algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define ll long longusing namespace std;set<string>st;int max_min_express(string s,bool flag){ int i=0,j=1,k=0,len=s.length(); while(i<len&&j<len&&k<len) { int t=s[(j+k)%len]-s[(i+k)%len]; if(t==0)k++; else { if(flag) { if(t>0) j+=k+1; else i+=k+1; } else { if(t>0) i+=k+1; else j+=k+1; } if(i==j) j++; k=0; } } return min(i,j);}string change(string s)//组合字符串{ int k=max_min_express(s,true); int len=s.length(); string str=""; for(int i=k+1; i<=k+len; i++) str+=s[i%len]; return str;}int main(){ int n; while(cin>>n) { string s; st.clear(); while(n--) { cin>>s; string str=change(s); st.insert(str); } cout<<st.size()<<endl; } return 0;}
阅读全文
0 0
- HDU2609 How many(字符串的最小表示法)
- HDU2609 How many(字符串的最小表示+set)
- hdu2609-字符串最小表示法|模拟|二分+lcp-How many
- hdu2609 How many (最小表示法)
- 最小表示法+hash hdu2609 How many
- HDU2609 How many(最小表示法)
- hdu2609 字符串的最小表示法模版
- HDU2609(字符串的最小表示法)
- How many 杭电oj 2609 hdu2609 最小表示
- hdu 2609 How many(字符串的最小表示法)
- hdu2609(最小表示法)
- hdu2609(最小表示法+set)
- HDU 2609 How Many [最小表示法] [字符串处理]
- HDU 2609 How many(字符串同构,最小表示法)
- hdu2609---How many
- HDU——2609How many(字符串的最小表示法+substr)
- HDU 2609 How Many最大最小表示法的模板
- How many-字典树+最小表示法
- response.setContentType()的作用及参数
- js 有没有一个方法会影响到另一个方法
- 第四周 项目2
- TensorFlow 曲线拟合
- spring ListableBeanFactory接口中getBeansOfType和BeanFactory接口的isTypeMatch方法实现分析
- HDU2609 How many(字符串的最小表示法)
- HDU 1873 看病要排队
- 移动端的iscroll
- 基于spring+springmvc+mybatis的图书管理系统
- hosts设置和ssh设置
- 如何解决 Linux 虚拟机磁盘设备名不一致的问题
- MongoDB详解
- ubuntu16.04 编译freeswitch1.9的视频mod_av模块
- ssh: connect to host localhost port 22: Connection refused