HDU 4162 Shape Number【字符串最小表示】
2012-03-14 18:27
344 查看
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).
View Code
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).
View Code
#include<stdio.h> #include<string.h> #define min(a,b)((a)<(b))?(a):(b) int Min(char s[],int len) { int i=0,j=1,k=0; while(i<len&&j<len&&k<len) { if(s[(i+k)%len]==s[(j+k)%len]) k++; else { if(s[(i+k)%len]>s[(j+k)%len]) i+=k+1; else j+=k+1; if(i==j) j++; k=0; } } return min(i,j); } char s[300001]; int main() { int i,len,k; char tmp; while(scanf("%s",s)!=EOF) { len=strlen(s); tmp=s[0]; for(i=0;i<len-1;i++) s[i]=(s[i+1]+8-s[i])%8+'0'; s[i]=(tmp+8-s[i])%8+'0'; k=Min(s,len); for(i=k;i<len;i++) printf("%c",s[i]); for(i=0;i<k;i++) printf("%c",s[i]); printf("\n"); } return 0; }
相关文章推荐
- 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 String Problem(KMP+字符串最小最大表示)
- HDU NO.4162 Shape Number(最小表示法循环输出字符串)
- hdu 2609 How many(字符串的最小表示法)
- HDU 2609 How Many [最小表示法] [字符串处理]
- TOJ 3771 HDU 4162 Shape Number / 最小表示法
- hdu 3374 String Problem(字符串最小最大表示法+kmp)
- String Problem HDU - 3374(字符串的最大最小表示)
- HDU——4162Shape Number(字符串的最小表示)
- HDU 4162 Shape Number(字符串,最小表示法)