Minimum Expression of String 字符串最小表示
2012-09-21 18:33
363 查看
十分详细的解释:http://hi.baidu.com/kfkkwlhvxcadotr/item/14a46a2b1f889e152a0f1c5f
几道相关例题的代码:
hdu 4162
——written by Lyon
几道相关例题的代码:
#include <cstdio> #include <cstring> #include <cassert> #include <algorithm> #include <set> #include <string> using namespace std; set<string> cnt; char buf[300001], tmp[300001]; int minExp(char *s) { int i = 0, j = 1, k = 0, t; int len = strlen(s); while (i < len && j < len && k < len) { t = s[(i + k) % len] - s[(j + k) % len]; if (!t) { k++; } else { if (t > 0) i = i + k + 1; else { j = j + k + 1; } if (i == j) j++; k = 0; } //printf("%d %d %d\n", i, j, k); } return min(i, j); } void work() { int len = strlen(buf); tmp[0] = (buf[0] - buf[len - 1] + 8) % 8 + '0'; for (int i = 1; i < len; i++){ tmp[i] = (buf[i] - buf[i - 1] + 8) % 8 + '0'; } int pos = minExp(tmp); for (int i = 0; i < len; i++) { buf[i] = tmp[(pos + i) % len]; } } int main() { while (~scanf("%s", buf)) { work(); printf("%s\n", buf); } return 0; }
hdu 4162
——written by Lyon
相关文章推荐
- String Problem HDU - 3374(字符串的最大最小表示)
- hdu 3374 String Problem kmp+字符串最小表示法+next数组性质
- bzoj 2176: Strange string 字符串最小表示法
- O - String Problem KMP 字符串最小表示法
- BZOJ 2176: Strange string【字符串最小表示法
- 处理字符串的外部表示(Handling External Representations of Strings)CFString
- HDU3374(String Problem)字符串-最小表示法+KMP
- LeetCode:minimum-depth-of-binary-tree(二叉树最小深度)
- [转]浅析“最小表示法”思想在字符串循环同构问题中的应用-HDU2609
- 字符串的最小表示法与有根树同构的判定
- 字符串最小表示法 O(n)算法
- C++的中英文字符串表示(string,wstring)
- 【字符串循环同构的最小表示法】
- [CareerCup] 1.1 Unique Characters of a String 字符串中不同的字符
- 环形字符串最小最大表示法
- 用lastIndexOf方法返回String对象内最后一次出现子字符串的字符位置的示例
- 【HDU5442 2015长春网络赛F】字符串最小表示法+函数逆用循环节法+翻转串字符串哈希法
- 字符串算法——查找有序数组旋转后的最小值(无重复元素)(Find Minimum in Rotated Sorted Array)
- [LeetCode] Number of Segments in a String 字符串中的分段数量
- Vijos 有根树的同构问题【字符串---最小表示法】