【HDU 4162】Shape Number(一阶差分链码+最小表示法)
2015-09-23 23:34
405 查看
【HDU 4162】Shape Number(一阶差分链码+最小表示法)
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1249 Accepted Submission(s): 593
Problem Description
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.
00110026202011676122
01100262020116761220
11002620201167612200
...
20011002620201167612
In this case, 00110026202011676122 is the shape number of the shape above.
Input
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.
Output
For each case, print the resulting shape number after the normalizations discussed above are performed.
Sample Input
Sample Output
Source
The 2011 Rocky Mountain Regional Contest
Recommend
lcy | We have carefully selected several similar problems for you: 4161 4163 4164 4165 4168
先处理一下输入串 说是啥求一阶差分链码。。反正根据题意就是把str[i]变成str[i+1]转到str[i]需要的步数 逆时针按图转
转换后跑一次最小表示法找出同构字符串中最小字典序即可
最小表示法这有几篇好文不错
http://www.cnblogs.com/wuhenqs/p/3201053.html 这是本题题解 感觉讲最小表示讲的挺详细的
http://blog.csdn.net/zy691357966/article/details/39854359
/article/1819422.html 这篇讲的比较浅显 能很快明白 但不太好深刻理解
此题代码如下:
Shape Number
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1249 Accepted Submission(s): 593
Problem Description
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.
00110026202011676122
01100262020116761220
11002620201167612200
...
20011002620201167612
In this case, 00110026202011676122 is the shape number of the shape above.
Input
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.
Output
For each case, print the resulting shape number after the normalizations discussed above are performed.
Sample Input
22234446466001207560 12075602223444646600
Sample Output
00110026202011676122 00110026202011676122
Source
The 2011 Rocky Mountain Regional Contest
Recommend
lcy | We have carefully selected several similar problems for you: 4161 4163 4164 4165 4168
先处理一下输入串 说是啥求一阶差分链码。。反正根据题意就是把str[i]变成str[i+1]转到str[i]需要的步数 逆时针按图转
转换后跑一次最小表示法找出同构字符串中最小字典序即可
最小表示法这有几篇好文不错
http://www.cnblogs.com/wuhenqs/p/3201053.html 这是本题题解 感觉讲最小表示讲的挺详细的
http://blog.csdn.net/zy691357966/article/details/39854359
/article/1819422.html 这篇讲的比较浅显 能很快明白 但不太好深刻理解
此题代码如下:
#include <bits/stdc++.h> using namespace std; char str[300100]; int Minimze(char *s, int len) { int i,j,k,t; i = k = 0; j = 1; 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; } } return min(i,j); } int main() { int len; while(~scanf("%s",str)) { len = strlen(str); str[len] = str[0]; for(int i = 0; i < len; ++i) str[i] = (str[i+1]-str[i]+8)%8+'0'; str[len] = 0; int pos = Minimze(str,len); printf("%s",str+pos); str[pos] = 0; puts(str); } return 0; }
相关文章推荐
- 《一课经济学》书摘笔记I
- 深入PHP内核之参数
- 汉诺塔
- 面对对象思想2
- 带你玩转Visual Studio——带你新建一个工程
- 2015第39周三
- Linux 入门常用命令
- Ubuntu 下 安装QQ 截图工具
- 第一行代码笔记2
- (八)使用可选参数
- 学习synchronized遇到的一点问题
- LeetCode Reverse Bits
- 迁移/home目录至新硬盘分区总结--无备份情况下
- mysql client 参数
- 全排列个数
- 【j360-boot】Spring-boot系列一(可能是最好的quick start)
- MDM_weeke1
- 深入分析iOS问题-performSelector:onThread:withObject:waitUntilDone
- R使用RMySQL包
- 转 jvm设置调优