• <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

            題意很簡單
            給出一個字符串,求一個最長沒有k模式重復的前綴
            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 (子串以字母開頭和結尾)
            • Both S1 and S2 contain exactly k alphabetic characters (子串包含K個字母)
            • For each alphabetic character c, the string S1 contains the same number of occurrences of c as the string S2. (子串中各個字母的數量相等)

            這就提示我們可以用字符串的最小表示來做
            最簡單的表示法就是"[a的個數] [b的個數] ..[z的個數]",然后用字符串來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 閱讀(174) 評論(0)  編輯 收藏 引用 所屬分類: data struct

            <2010年11月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            99久久伊人精品综合观看| 日韩久久久久中文字幕人妻 | 很黄很污的网站久久mimi色| 精品久久久无码中文字幕| 久久A级毛片免费观看| 无码人妻久久久一区二区三区| 久久国产色av免费看| 久久亚洲日韩看片无码| 久久久久久精品免费看SSS| 久久久www免费人成精品| 亚洲国产精品一区二区久久hs| 亚洲精品第一综合99久久| 色狠狠久久综合网| 亚洲色欲久久久综合网| 久久久久久久人妻无码中文字幕爆| 色88久久久久高潮综合影院| 国产精品久久久亚洲| 久久综合九色综合精品| 久久精品亚洲精品国产欧美| 亚洲日本va午夜中文字幕久久 | 香蕉久久夜色精品国产尤物| 久久精品国产2020| 老司机国内精品久久久久| 久久综合九色欧美综合狠狠| 久久人人爽人人人人爽AV| 精品久久久久久成人AV| 久久精品成人影院| 亚洲中文字幕久久精品无码喷水| 久久99精品国产麻豆| 国产精品日韩欧美久久综合| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 亚洲?V乱码久久精品蜜桃| 奇米综合四色77777久久| 国产成人无码精品久久久免费| 一级女性全黄久久生活片免费| 久久精品国产亚洲精品2020| 国产精品成人无码久久久久久| 亚洲人成无码久久电影网站| 久久久久中文字幕| 久久天天躁狠狠躁夜夜2020一| AV无码久久久久不卡网站下载|