hdu2609(最小表示法)
题意:有n个环形字符串,一个环形字符串移动会形成不能的字符串,我们把它们看作同一串字符串,求有多少个不同的字符串.......
思路:用最小表示发将一个环形串的最小字典序找出来,然后让这个环形串按照这个顺序来组成一个新的串,其他串都这样处理,然后去重,输出结果就是了.......
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[10005][105];
struct node
{
char ch[105];
}t[10005];
int cmp(const node a,const node b)
{
if(strcmp(a.ch,b.ch)<0)
return 1;
else
return 0;
}
int work(int m,char str[])
{
int i,j,l;
i=0; j=1;
while(i<m && j<m)
{
for(l=0;l<m;l++)
if(str[(i+l)%m]!=str[(j+l)%m]) break;
if(l>m) break;
if(str[(i+l)%m] > str[(j+l)%m])
i=i+l+1;
else
j=j+l+1;
if(i==j) j=i+1;
}
if(i<j) return i;
return j;
}
int main()
{
int n;
while(scanf("%d",&n)>0)
{
for(int i=1;i<=n;i++)
scanf("%s",s[i]);
for(int i=1;i<=n;i++)
{
int len=strlen(s[i]);
int cnt=work(len,s[i]);
strcpy(t[i].ch,s[i]+cnt);
s[i][cnt]='\0';
strcpy(t[i].ch+len-cnt,s[i]);
}
sort(t+1,t+1+n,cmp);
int sum=1;
for(int i=2;i<=n;i++)
{
if(strcmp(t[i-1].ch,t[i].ch)!=0)
sum++;
}
printf("%d\n",sum);
}
return 0;
}
hdu2609(最小表示法)的更多相关文章
- hdu2609 最小表示法
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- hdu2609最小表示法
#include <iostream> #include <algorithm> #include <string.h> #include <cstdio&g ...
- 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 How many 字典树+最小表示法
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell meHow many ...
- HDU 4162 Shape Number (最小表示法)
题意:给你一串n个数,求出循环来看一阶差的最小字典序:数字串看成一个顺时针的环,从某一点开始顺时针循环整个环,保证字典序最小就是答案 例如给你 2 1 3 就会得到(1-2+8 注意题意负数需要加8) ...
- POJ 1635 树的最小表示法/HASH
题目链接:http://poj.org/problem?id=1635 题意:给定两个由01组成的串,0代表远离根,1代表接近根.相当于每个串对应一个有根的树.然后让你判断2个串构成的树是否是同构的. ...
- HDU 2609 最小表示法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...
- HDU 4162 最小表示法
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162 题意:给定一个只有0-7数字组成的串.现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字 ...
- POJ 1509 最小表示法
题目链接:http://poj.org/problem?id=1509 题意:给定一个字符串,求一个起点使字符串从该起点起的字符串字典序最小[题目的字符串起点从1开始] 思路:最小表示法模板题 #de ...
随机推荐
- Zuul使用Ribbon配置自动重试
spring cloud的版本不断演进,导致很多配置的配置方式不断改变,有时某个配置在一个版本里面默认是true,后边一升级默认成了false,这点让人有点不爽. 言归正传 0.所使用版本 sprin ...
- 前端工程精粹(一):静态资源版本更新与缓存(附精简js的工具)
转自:http://www.infoq.com/cn/articles/front-end-engineering-and-performance-optimization-part1/ 每个参与过开 ...
- PHP-Open Flash Chart报表生成
下载: http://www.cnblogs.com/huangcong/archive/2013/01/27/2878650.html 安装: 解压ZIP包, 将open-flash-chart.s ...
- ubuntu(14.04版本) 配置虚拟环境(一个ip对应多个域名)
以下操作是建立在apahce安装成功的情况下 1.配置本地的host. 假设虚拟主机上的ip是:192.168.1.51,那么客户端本地的host可以配置成:
- Clipboard.GetImage() Clipboard获取粘贴板内容为null的解决办法
将线程启动模式设置为 sta 单线程 简介 STA: Single-Thread Apartment, 中文叫单线程套间.就是在COM库初始化的时候创建一个内存结构,然后让它和调用CoIn ...
- JMeter学习笔记--使用URL回写来处理用户会话
如果测试的Web应用系统使用URL回写而非Cookie来保存会话信息,那么测试人员需要做一些额外的工作来测试web站点 为了正确回应URL回写,JMeter需要解析从服务器收到的HTML,并得到唯一的 ...
- JS高级心法——作用域链
首先我们来看两个js中的代码: <script type="text/javascript"> var c=5; function t1(){ var d=6 f ...
- python 中hive 取日期时间的方法
#!/usr/bin/env python3 import sys import os import time, datetime sys.path.append(os.getenv('HIVE_TA ...
- app hybrid
package com.note.testcases; /** * * The MIT License (MIT) * * Copyright (c) 2016 Alejandro Gómez Mor ...
- linux shell 删除指定文件夹下面 名称不包含指定字符的文件
find /app/jenkins/jenkins/jobs/scam/* ! -name config.xml | xargs rm -rf 删除/app/jenkins/jenkins/jobs/ ...