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的字符串,求一个起点使字符串从该起点起的 ...
随机推荐
- 大数(bzoj 4542)
/* 想了半天莫队,不知道咋转移,需要动下脑子. 有一个很显然的结论是如果(l,r)是P的倍数,那么s[l...n]%P=s[r+1...n]%P. 根据这个东西,我们预处理出所有的后缀%P的余数,接 ...
- php——配合QQ邮箱发送邮件
最近做一个域名管理系统的项目,实现在域名还有三十天的时候系统发送邮件到QQ邮箱从而提醒续费: 这里运用到了phpmailer; 1:getAll函数: function getAll($con,$sq ...
- AC日记——草地排水 codevs 1993
1993 草地排水 USACO 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在农夫约翰的农场上,每 ...
- Java 新手的通病
一:对算法和数据结构不熟悉 为什么我先拿“数据结构和算法”说事捏?这玩意是写程序最最基本的东东.不管你使用 Java 还是其它的什么语言,都离不开它.而且这玩意是跨语言的,学好之后不管在哪门语言中都能 ...
- T1079 回家 codevs
http://codevs.cn/problem/1079/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver~死坑 题目描述 Description 现在是晚 ...
- STM32F10x_StdPeriph_Driver_3.5.0(中文版).chm的使用
以熟悉的固件库函数说明中函数GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_IintTypeDef *GPIO_InitStructure)为例 GPIOA...G ...
- SPOJ 26108 TRENDGCD - Trending GCD
Discription Problem statement is simple. Given A and B you need to calculate S(A,B) . Here, f(n)=n, ...
- Python资料大全
说明:以下文章为转载,有英文原文和中文整理翻译,对原作者和译者的工作表示极大感谢!!! 英文原文:https://github.com/vinta/awesome-python 中文译文:https: ...
- 洛谷 P1034 矩形覆盖
P1034 矩形覆盖 题目描述 在平面上有nn个点(n \le 50n≤50),每个点用一对整数坐标表示.例如:当 n=4n=4 时,44个点的坐标分另为:p_1p1(1,11,1),p_2p2( ...
- Spring拦截器从Request中获取Json格式的数据
7 package com.newpp.core.interceptor; 8 9 import java.io.BufferedReader; 10 import java.io.ByteArray ...