hdu2609 How many (最小表示法)
来源:互联网 发布:淘宝卖家怎样添加客服 编辑:程序博客网 时间:2024/05/16 17:54
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609
题解:这个问题的本质就在于排序(非降序)之后的序列是原序列的“最小表示”,如果两个序列的“最小表示”相同则两者就相同,否则就不相同。
#include <cstdio>#include <cstring>#include <string>#include <set>#define MAXN 102using namespace std;set<string> S;char str[MAXN],tpstr[MAXN];/*用最小表示法求字符串S的最小字典序返回字典序最小的串的首字母位置*/int getMin(){int i=0,j=1,k=0,tp;int len=strlen(tpstr);while(i<len&&j<len&&k<len){tp=tpstr[(i+k)%len]-tpstr[(j+k)%len];if(!tp)k++;else{if(tp>0)i+=(k+1);elsej+=(k+1);if(i==j)j++;k=0;}}return i<j?i:j;}int main(){int n,sum,i,j,k,index,len;set<string>::iterator iter;while(scanf("%d",&n)!=EOF){sum=0;S.clear();for(i=0;i<n;++i){scanf("%s",tpstr);index=getMin();j=0;for(k=index;tpstr[k]!='\0';++k){str[j]=tpstr[k];j++;}for(k=0;k<index;++k){str[j]=tpstr[k];j++;}str[j]='\0';if(!S.count(str)){sum++;S.insert(str);}}printf("%d\n",sum);}return 0;}
- hdu2609 How many (最小表示法)
- 最小表示法+hash hdu2609 How many
- HDU2609 How many(最小表示法)
- hdu2609-字符串最小表示法|模拟|二分+lcp-How many
- HDU2609 How many(字符串的最小表示法)
- How many 杭电oj 2609 hdu2609 最小表示
- HDU2609 How many(字符串的最小表示+set)
- hdu2609(最小表示法)
- hdu2609(最小表示法+set)
- hdu2609---How many
- hdu2609 字符串的最小表示法模版
- HDU2609(字符串的最小表示法)
- How many-字典树+最小表示法
- hdu 2609 How many(最小表示法)
- [最小表示法] hdu 2609 How many
- [最小表示法] HDU 2609 How many
- HDU - 2609 How many(最小表示法)
- HDU 2609 How many(最小表示法)
- MySql按周,按月,按日分组统计数据
- 渐进式jpeg(progressive jpeg)图片及其相关
- vs2010未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
- shell条件测试
- 设计一个新文件系统。
- hdu2609 How many (最小表示法)
- Mac+IPAD上使用wireshark抓包
- 《史蒂夫·乔布斯传》官方正式中文版电子书(高清晰完整版)
- Servlet && tomcat
- 在Oracle中把标量子查询转换为复合子查询
- 基础知识--确定本机到另外一台机器中路由器的个数
- Java和C++中的嵌套类讨论
- 最新版ZMQ3.2.3
- 实作PHP表单图形验证码验证码