• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            pku2119 God of the Vile Baskers 字符串的最小表示+hash

            題意很簡(jiǎn)單
            給出一個(gè)字符串,求一個(gè)最長(zhǎng)沒有k模式重復(fù)的前綴
            Two strings S1 and S2 are k-identical up to permutation of letters if:

            • Both S1 and S2 start and end with an alphabetic character (子串以字母開頭和結(jié)尾)
            • Both S1 and S2 contain exactly k alphabetic characters (子串包含K個(gè)字母)
            • For each alphabetic character c, the string S1 contains the same number of occurrences of c as the string S2. (子串中各個(gè)字母的數(shù)量相等)

            這就提示我們可以用字符串的最小表示來(lái)做
            最簡(jiǎn)單的表示法就是"[a的個(gè)數(shù)] [b的個(gè)數(shù)] ..[z的個(gè)數(shù)]",然后用字符串來(lái)hash
            貼代碼

             1import java.io.*;
             2import java.util.*;
             3public class Main {
             4
             5    /**
             6     * @param argsarg0
             7     */

             8    static HashSet<String> refer=new HashSet<String>();
             9    static int count[]=new int[26];
            10    static String hash()
            11    {
            12        StringBuffer tmp=new StringBuffer();
            13        for(int i=0;i<26;i++)
            14            tmp.append(count[i]);
            15        return tmp.toString();
            16    }

            17    public static void main(String[] args) throws IOException{
            18        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
            19        while(true)
            20        {
            21            int num=Integer.parseInt(in.readLine());
            22            if(num==0break;
            23            refer.clear();
            24            String str=in.readLine();
            25            Arrays.fill(count, 0);
            26            int pos,last=-1,co=0;
            27            str=str.toLowerCase();
            28            for(++last;last<str.length()&&!Character.isLowerCase(str.charAt(last));last++);
            29            for(pos=0;pos<str.length();pos++)
            30            {
            31                if(Character.isLowerCase(str.charAt(pos)))
            32                {
            33                    count[str.charAt(pos)-'a']++;
            34                    co++;
            35                }

            36                if(co==num)
            37                {
            38                    String ha=hash();
            39                    if(refer.contains(ha))
            40                        break;
            41                    else
            42                    {
            43                        refer.add(ha);
            44                        count[str.charAt(last)-'a']--;
            45                        for(++last;last<str.length()&&!Character.isLowerCase(str.charAt(last));last++);
            46                        co--;
            47                    }

            48                }

            49                
            50            }

            51            System.out.println(pos);
            52                    
            53            
            54        }

            55
            56    }

            57
            58}

            59
            60

            posted on 2010-10-31 00:00 yzhw 閱讀(172) 評(píng)論(0)  編輯 收藏 引用 所屬分類: data struct

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導(dǎo)航

            統(tǒng)計(jì)

            公告

            統(tǒng)計(jì)系統(tǒng)

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            久久亚洲私人国产精品vA| 久久国产精品无| 69SEX久久精品国产麻豆| 久久亚洲国产成人精品性色 | 国产精品成人无码久久久久久| 中文字幕成人精品久久不卡| 久久国产精品波多野结衣AV| 欧美精品国产综合久久| 精品久久久久中文字幕日本| 久久久久无码精品| 久久精品国产网红主播| 欧美国产精品久久高清| 99精品国产在热久久无毒不卡| 日日狠狠久久偷偷色综合96蜜桃| 久久综合亚洲鲁鲁五月天| 精品无码久久久久久久久久 | 久久久精品日本一区二区三区| 亚洲色欲久久久综合网东京热| 51久久夜色精品国产| 人人狠狠综合久久88成人| 人人狠狠综合久久亚洲| 国产亚洲精久久久久久无码AV| 国产毛片欧美毛片久久久| 久久性精品| 久久电影网| 精品综合久久久久久88小说| 国产精品一久久香蕉产线看| 亚洲愉拍99热成人精品热久久| 亚洲乱码日产精品a级毛片久久| 国产农村妇女毛片精品久久| 99久久99这里只有免费的精品| 亚洲狠狠婷婷综合久久久久| 久久丫忘忧草产品| 久久国产亚洲精品| 97久久婷婷五月综合色d啪蜜芽 | 久久久久高潮毛片免费全部播放| 亚洲欧美日韩久久精品| 久久精品综合网| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 亚洲国产香蕉人人爽成AV片久久 | 精品无码久久久久国产动漫3d|