zoukankan      html  css  js  c++  java
  • hdu 4162 Shape Number

    Shape Number

    Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 798    Accepted Submission(s): 387


    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
     
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <algorithm>
     4 #include <string.h>
     5 #include <set>
     6 using namespace std;
     7 char s[400000],a[400000];
     8 int moremin(char s[],int l)
     9 {
    10     int i,j,k,t;
    11     i=k=0,j=1;
    12     while(i<l&&j<l&&k<l)
    13     {
    14         int t=s[i+k>=l?i+k-l:i+k]-s[j+k>=l?j+k-l:j+k];
    15         if(!t)k++;
    16         else
    17         {
    18             if(t>0)i+=k+1;
    19             else j+=k+1;
    20             if(i==j)j++;
    21             k=0;
    22         }
    23     }
    24     return (i>j?j:i);
    25 }
    26 int main()
    27 {
    28     int i;
    29     while(~scanf("%s",a))
    30     {
    31         int l=strlen(a);
    32         for(i=0;i<l;i++)
    33         if(a[i+1>=l?i+1-l:i+1]>=a[i])
    34         s[i]=a[i+1>=l?i+1-l:i+1]-a[i]+'0';
    35         else s[i]=8+a[i+1>=l?i+1-l:i+1]-a[i]+'0';
    36         s[i]='';
    37         int x=moremin(s,l);
    38         for(i=0;i<l;i++)
    39         putchar(s[i+x>=l?i+x-l:i+x]);
    40         puts("");
    41     }
    42 }
    View Code
  • 相关阅读:
    解释机器学习模型的一些方法(一)——数据可视化
    机器学习模型解释工具-Lime
    Hive SQL 语法学习与实践
    LeetCode 198. 打家劫舍(House Robber)LeetCode 213. 打家劫舍 II(House Robber II)
    LeetCode 148. 排序链表(Sort List)
    LeetCode 18. 四数之和(4Sum)
    LeetCode 12. 整数转罗马数字(Integer to Roman)
    LeetCode 31. 下一个排列(Next Permutation)
    LeetCode 168. Excel表列名称(Excel Sheet Column Title)
    论FPGA建模,与面向对象编程的相似性
  • 原文地址:https://www.cnblogs.com/ERKE/p/3832942.html
Copyright © 2011-2022 走看看