HDU2609 How many —— 最小表示法
题目链接:https://vjudge.net/problem/HDU-2609
How many
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3272 Accepted Submission(s): 1457
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 <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MAXN = 1e4+; char s[MAXN][], tmp[]; int cmp(const void *a,const void *b)
{
return (strcmp((char*)a,(char*)b));
} int getmin(char *s, int len) //返回最小表示法的始端
{
int i = , j = , k = ;
while(i<len && j<len && k<len)
{
int t = s[(i+k)%len]-s[(j+k)%len];
if (!t) k++;
else
{
if (t>) i += k+;
else j += k+;
if (i==j) j++;
k = ;
}
}
return i<j?i:j;
} int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
for(int i = ; i<=n; i++)
{
scanf("%s", tmp);
int len = strlen(tmp);
int k = getmin(tmp, len);
for(int j = ; j<len; j++)
s[i][j] = tmp[(k+j)%len];
s[i][len] = ; //!!
}
qsort(s+, n, sizeof(s[]), cmp); int ans = ;
for(int i = ; i<=n; i++)
if(i== || strcmp(s[i], s[i-]))
ans++; printf("%d\n", ans);
}
}
HDU2609 How many —— 最小表示法的更多相关文章
- 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 ...
- hdu2609 最小表示法
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- 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 ...
- UVA 1314 最小表示法
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36117 题意:给定长度为n的字符串,求一个起点使字符串从该起点起的 ...
随机推荐
- Spring Task Schedule 及多线程
http://spring.io/blog/2010/01/05/task-scheduling-simplifications-in-spring-3-0/‘ http://ekramalikazi ...
- grafana 安装 和 Nginx 、EL 联调
https://blog.csdn.net/u010735147/article/details/80943593
- Delphi中的操作二进制文件的两个重要函数
Delphi中的操作二进制文件的两个重要函数 对于通过Byte数组进行文件操作的,在FTP中经常会使用到,我也是在Delphi调用Web Service进行文件的上传和下载时找到这两个函数的,挺好用的 ...
- the import org.springframewok.test cannot be resolved
在写Spring的单元测试时遇见了问题,注解@ContextConfiguration和SpringJUnit4ClassRunner.class无法导包.手动导包后错误为“the import or ...
- javaWeb_Request对象
首先说一下Http协议 一.Http协议的概念及作用 1.什么是HTTP协议? (HTTP,HyperText Transfer Protocol)超文本传输协议, 是互联网上应用最为广泛的一种网络协 ...
- Spring 详解(二)------- AOP关键概念以及两种实现方式
目录 1. AOP 关键词 2. AOP 的作用 3. AOP 的通知类型 4. 基于 xml 的配置方式 5. 基于注解的配置方式 6. 切面的优先级 7. 重用切点表达式 8. 两种方式的比较(摘 ...
- BZOJ1017魔兽地图DotR 樹形DP
@(BZOJ)[樹形DP, 三維DP] Description DotR (Defense of the Robots) Allstars是一个风靡全球的魔兽地图,他的规则简单与同样流行的地图DotA ...
- SQL Server I/O Basics
SQL Server I/O Basics Chapter 1http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlIO ...
- Java主线程等待所有子线程执行完毕再执行解决办法(转)
方法一: Thread.join()方法,亲测可行,thread.join()方法 Vector<Thread> ts = new Vector<Thread>(); for ...
- OllyDBG找到按钮的处理函数
最近系统有点慢,就想优化一下,于是下了个XX大师.结果要注册才行,看来可以用来练练手了.OD一下,靠还加了壳,偶就是用一下,就不脱你了.开始在弹出窗口MessageBoxA下断,伊,结果不是用的这个函 ...