zoukankan      html  css  js  c++  java
  • hdu2609最小表示法

    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <cstdio>
    #include <vector>
    using namespace std;
    const int maxn=10005;
    struct elem
    {
        char str[105];
        int len;
        bool operator <(const elem &rhs)const{
           return len<rhs.len||(len==rhs.len&&strcmp(str,rhs.str)<=0);
        }
        bool operator == (const elem &rhs)const{
           return len==rhs.len&&strcmp(str,rhs.str)==0;
        }
    }P[maxn];
    char s[105];
    int MinRepresstation(char * S, int len ) {
          int i = 0, j = 1, k = 0;
          while(i < len && j < len)
            {
                k = 0;
               while(k < len && S[(i + k)%len] == S[(j + k)%len])
                k++;
               if(k >= len)
                break;
               if(S[(i + k)%len] > S[(j + k)%len])
                i = max(i + k + 1, j + 1);
               else
                j = max(i + 1, j + k + 1);
            }
          return min(i ,j);
    }
    int main()
    {
        int n;
        while(scanf("%d",&n)==1)
            {
                 for(int i=0; i<n; i++)
                    {
                          scanf("%s",s);
                          P[i].len=strlen(s);
                          int d=MinRepresstation(s,P[i].len);
                          for(int j=0;j<P[i].len; j++)
                            P[i].str[j]=s[ (d+j)%P[i].len ];
                          P[i].str[P[i].len]=0;
                    }
                 sort(P,P+n);
                 int num=unique(P,P+n)-P;
                 printf("%d
    ",num);
    
            }
    
        return 0;
    }
  • 相关阅读:
    Servlet 规范 简介
    Redis简介
    some tips
    初识Servlet
    JVM基础知识
    使用typora编辑博客
    航海が始まる日
    比较好的IT教程网
    vue 使用心得---工作中一些关键点
    Vue父组件主动获取子组件的数据和方法
  • 原文地址:https://www.cnblogs.com/Opaser/p/4810441.html
Copyright © 2011-2022 走看看