最小表示法
来源:互联网 发布:淘宝发布宝贝 压缩包 编辑:程序博客网 时间:2024/06/05 20:27
http://www.tuicool.com/articles/bmERbm 这个讲的还行
How many HDU - 2609
题意:给你很多个字符串,然后他们可以旋转成为相同的字符串,就是同一个字符串,问有多少个不同的字符串
分析:我们要把这些字符串都变成相同的一种,这样,我们就可以直接知道有多个不同的字符串了。
最小表示法,将一个字符串旋转成为字典序最小的字符串
这个题就是把每个字符串都用最小表示法,然后set来看一下有多个不同的字符串
注意set 里面不要放数组。。比如set < char * > 或者set < int * >
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>#include <set>using namespace std;const int maxn = 110;char s[maxn];set<string> Set;int sum=0;void getminsub(char *s){ int i=0,j=1,k=0,len=strlen(s); while(i<len&&j<len&&k<len) { if(k>=len) break; int ni=i+k,nj=j+k; if(ni>=len) ni-=len; if(nj>=len) nj-=len; if(s[ni]<s[nj]) { j=j+k+1; k=0; } else if(s[ni]>s[nj]) { i=i+k+1; k=0; } else k++; if(i==j) j++; } i=min(i,j); string ans=""; int h=0; while(h<len) { if(i>=len) i-=len; ans+=s[i]; h++; i++; } if(Set.count(ans)==0){ sum++; Set.insert(ans); } return ;}int main(){ int n; while(scanf("%d",&n)!=EOF) { Set.clear(); sum=0; for(int i=0;i<n;i++) { scanf("%s",s); getminsub(s); } printf("%d\n",sum); } return 0;}
阅读全文
1 0
- 最小表示法
- poj1509(最小表示法)
- hdu4162(最小表示法)
- 最小表示法
- 最小表示法
- 最小表示法
- 最小表示法模板
- 最小表示法
- 最小表示法+uva719
- 最小表示法
- 最小表示法
- poj1509最小表示法
- 字符串最小表示法
- poj1509 最小表示法
- 最小表示法
- poj1509 最小表示法
- 【模版】最小表示法
- 最小表示法
- squid透明代理配置
- Mapper类详解
- Configuration类详解
- Brew error: Could not symlink, xx/xx/xxx is not writable
- Properties类
- 最小表示法
- 设置环境变量的方法
- Swift3豆瓣电台
- STM32 Tutorial: #4 Using STM32Duino
- hadoop核心逻辑shuffle代码分析-map端
- spark shuffle内在原理说明
- springMvc和struts2区别
- 贪吃蛇C语言代码(window版本)
- Linux学习笔记之七