Question:
A series of chaincodes are represented by the minimum difference representation.
Ideas:
It is actually a template Question of the minimum representation...
Code:
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<map>#include<set>#include<vector>#include<queue>#include<cstdlib>#include<ctime>#include<cmath>#include<bitset>using namespace std;#define N 600010#define inf 50000000int n;int a[N];int GetMin() { int i, j, k, len = n; for (i = 0, j = 1; i < len && j < len;) { for (k = 0; k < len && a[i + k] == a[j + k]; k++) ; if (k >= len) break; if (a[i + k] < a[j + k]) j += k + 1; else i += k + 1; if (i == j) j++; } return i;}char str[N];int main() { while (~scanf("%s", str)) { n = strlen(str); for (int i = 0; i < n; i++) a[i] = str[i] - '0'; int t = a[0]; for (int i = 0; i < n - 1; i++) a[i] = (a[i + 1] - a[i] + 8) % 8; a[n - 1] = (t - a[n - 1] + 8) % 8; for (int i = 0; i < n; i++) a[i + n] = a[i]; int i = GetMin(); for (int j = 0; j < n; j++) printf("%d", a[i + j]); printf("\n"); } return 0;}
HDU 4162 shape number