Shape Number HDU
来源:互联网 发布:java开发百度云播放器 编辑:程序博客网 时间:2024/05/22 23:28
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
题意:给你一个串 新串每个字母是旧串的(两位相减+8)%8,再求最小表示法
#include <bits/stdc++.h>using namespace std;int a[300100];int getMax(int a[], int n){ int i, j, k; for(i = 0, j = 1; i<n&&j<n; ) { for(k = 0; k<n&&a[i+k]==a[j+k]; k++) ; if(k>=n) break; if(a[i+k]<a[j+k]) j += k+1; else i += k+1; if(i == j) j++; } return i;}int main(){ string s; while(cin>>s) { int len=s.length(); for(int i=0;i<s.length()-1;i++) { a[i]=(s[i+1]-'0')-(s[i]-'0'); if(a[i]<0) a[i]+=8; } a[len-1]=(s[0]-'0')-(s[len-1]-'0'); if(a[len-1]<0) a[len-1]+=8; int pos=getMax(a,len); for(int i=0;i<len;i++) printf("%d",a[(pos+i)%len] ); printf("\n"); }}
- HDU 4162 Shape Number
- HDU 4162 Shape Number
- HDU 4162 Shape Number
- HDU 4162 Shape Number
- Shape Number HDU
- Shape Number HDU
- 【最小表示法】HDU-4162-Shape Number
- HDU 4162 Shape Number 最小表示法
- HDU 4162 Shape Number(最小表示法)
- LA - 5734(hdu - 4162) - Shape Number(指针扫描+贪心)
- TOJ 3771 HDU 4162 Shape Number / 最小表示法
- hdu 4162 Shape Number(最小表示法)
- HDU 4162 Shape Number(字符串,最小表示法)
- 【HDU 4162】Shape Number(一阶差分链码+最小表示法)
- uva 5734 Shape Number
- HDU4162 Shape Number
- Shape of HDU / HDU
- HDU NO.4162 Shape Number(最小表示法循环输出字符串)
- 《C语言入门经典》习题7.1(仅供与某人讨论使用)
- 消息队列应用场景
- SQLiteDatabase中query、insert、update、delete方法参数说明
- Java 将HTML文件转换成PDF(Windows和linux)
- CenterOS7安装Redis,测试 Jedis 连接超时(connect timed out)
- Shape Number HDU
- 9-4(线段树最大值定位,区间合并)
- 怎样用mysql查询语句得到下方表格
- 哈夫曼树
- 输出一个矩形(长方形)
- 字节流的操作(3+1)
- JDK提供复制文件三种方式
- 技术人生(20) ——ORA-01555错误启示录
- 序列化与反序列化