TOJ 3771 HDU 4162 Shape Number / 最小表示法
2013-08-14 19:53
471 查看
Shape Number
时间限制(普通/Java):10000MS/30000MS 运行内存限制:65536KByte描述
In computer vision, a chain code is a sequence of numbers representing directions when following the contour of an object. For example, the following figure shows the contour represented by the chain code 22234446466001207560
(starting at the upper-left corner).
Two chain codes may represent the same shape if the shape has been rotated, or if a different starting point is chosen for the contour. To normalize the code for rotation, we can compute the first difference of the chain code
instead. The first difference is obtained by counting the number of direction changes in counterclockwise direction between consecutive elements in the chain code (the last element is consecutive with the first one). In the above code, the first difference
is
00110026202011676122
Finally, to normalize for the starting point, we consider all cyclic rotations of the first difference and choose among them the lexicographically smallest such code. The resulting code is called the shape number.
0011002620201167612201100262020116761220
11002620201167612200
...
20011002620201167612
In this case, 00110026202011676122 is the shape number of the shape above.
输入
The input consists of a number of cases. The input of each case is given in one line, consisting of a chain code of a shape. The length of the chain code is at most 300,000, and all digits in the code are between 0 and 7 inclusive. The contour may intersect
itself and needs not trace back to the starting point.
输出
For each case, print the resulting shape number after the normalizations discussed above are performed.
样例输入
22234446466001207560 12075602223444646600
样例输出
0011002620201167612200110026202011676122
就是首先按题意生成一个字符串 这个字符串是循环的 求它字典序最小的一个 可以学习一下最小表示法
#include <stdio.h> #include <string> char a[300010],str[300010]; int work(int m) { 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; } main() { int i,len,k; while(scanf("%s",a)!=EOF) { len = strlen(a); for(i = 0;i < len; i++) { if(a[(i+1)%len]>=a[i]) str[i] = a[(i+1)%len] - a[i] + '0'; else str[i] = 8 + a[(i+1)%len] - a[i] + '0'; } k = work(len); //printf("%d\n",k); for(i = 0; i < len; i++) { printf("%c",str[(i+k)%len]); } puts(""); } }
相关文章推荐
- 【最小表示法】HDU-4162-Shape Number
- Shape Number HDU - 4162(最小表示法)
- HDU 4162 Shape Number 最小表示法
- hdu 4162 Shape Number 最小表示法
- hdu 4162 Shape Number(最小表示法)
- HDU 4162 Shape Number(最小表示法)
- HDU 4162 Shape Number 最小表示法
- HDU 4162 Shape Number【字符串最小表示】
- hdu 4162 Shape Number【循环字符串最小表示法】模板学习
- HDU 4162 Shape Number (最小表示法)
- HDU 4162 Shape Number(最小表示法)
- 字符串_最小表示法求循环串的最小序列(HDU_4162)
- 【HDU 4162】Shape Number(一阶差分链码+最小表示法)
- HDU 3374 KMP 最大表示法 最小表示法
- HDU 1954 Subway tree systems(树的同构,树的最小表示)
- Hdu 4013 Distinct Subtrees (状态压缩枚举+树的最小表示)
- hdu 2609 How many(最小表示法)
- 【字符串最小表示】HDU 2609
- String Problem HDU - 3374 (最大最小表示法)
- HDU——4162Shape Number(字符串的最小表示)