poj 3189 二分+多重匹配
poj 2250 输出LCS

poj 1509 最小表示法

scturtle posted @ 2010年11月20日 18:36 in algorithm , 3336 阅读

最小表示法即寻找使循环串最小字典序的起始位置.

详见周源的ppthttp://www.chhaya.me/?p=229.

基本上就是两个指针i=0,j=1.从s[i]和s[j]开始比较第k个字符是否相同,当k==len时,返回i,j中的最小值.当s[i+k]和s[j+k]不相同时,若s[i+k]>s[j+k]则可见从s[i+1]到s[i+k]都不会是最小字典序的起始位置,所以i=i+k+1.当s[i+k]<s[j+k]时同理.若移动后i==j则使正在移动的那个指针++.然后从新的s[i]和s[j]开始比较.

#include <cstdio>
#include <cstring>

int mins(const char *s)
{
    int len=strlen(s);
    if(len==0||len==1) return 0;
    int i=0,j=1,k;
    char ci,cj;
    do
    {
        for(k=0;k<len;k++)
        {
            ci=s[(i+k)%len];
            cj=s[(j+k)%len];
            if(ci!=cj) break;
        }
        if(k==len) break;
        else if(ci>cj) 
        {
            i=i+k+1;
            if(i==j) i++;
        }
        else 
        {
            j=j+k+1;
            if(j==i) j++;
        }
    }while(1);
    return i<j?i:j;
}

char s[10001];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int cas;scanf("%d",&cas);
    while(cas--)
    {
        scanf("%s",s);
        printf("%d\n",mins(s)+1);
    }
}

 

Karnataka 1st Class 说:
2023年9月23日 17:18

Karnataka Board Elementary Syllabus 2024 is Designed in Accordance with the NCERT Based Guidelines and helps Students to get an Overview of the Kannada, English Medium All Subject, DSERT Karnataka keeps a 1st Class Exam Pattern with the aim to Provide a Quality Education for All Students, On the basis of the Current Educational Demands.Students Should Download the Respective Stream wise Karnataka 1st Class Syllabus 2024 Karnataka Class Exam Syllabus 2024 Subjects of Kannada, English, Mathematics, EVS Pdf Format Provide Check the same From our page here, So, Students need to Start Their Preparation by first Downloading the Stream wise DSERT Karnataka Curriculum Syllabus 2024 Latest Edition.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter