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

            pku1174 Contact 位處理+Hash

            題意大概是給出一個字符串,要求求出長度范圍在[a,b]區間內最大頻率子串
            看到這道題,我第一反應是后綴數組。。。結果悲劇的TLE了。。后來觀察到時01串,然后就想到了位壓縮,下次做題一定要注意,關注題目的特殊性。。
             1 import java.io.*;
             2 import java.util.*;
             3 public class Main {
             4 
             5     /**
             6      * @param args
             7      */
             8     static class cmp implements Comparator<String>
             9     {
            10         public int compare(String a,String b)
            11         {
            12             if(a.length()!=b.length())
            13                 return b.length()-a.length();
            14             else
            15                 return b.compareTo(a);
            16         }
            17     }
            18     public static void main(String[] args) throws IOException {
            19         BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
            20         TreeMap<Integer,ArrayList<String> > refer=new TreeMap<Integer,ArrayList<String> >(Collections.reverseOrder()); 
            21         HashMap<Integer,Integer> trefer=new HashMap<Integer,Integer>();
            22         int a=Integer.parseInt(in.readLine());
            23         int b=Integer.parseInt(in.readLine());
            24         int n=Integer.parseInt(in.readLine());
            25         String str=in.readLine();
            26         for(int len=a;len<=b;len++)
            27         {
            28             if(len>str.length()-1continue;
            29             int pos=0;
            30             int tmp=0;
            31             for(pos=0;pos<len;pos++)
            32                 tmp=(tmp<<1)|(str.charAt(pos)=='1'?1:0);
            33             trefer.clear();
            34             trefer.put(tmp, 1);
            35             for(pos=len;pos<str.length()-1;pos++)
            36             {
            37                 tmp=((tmp<<1)&((1<<len)-1))|(str.charAt(pos)=='1'?1:0);
            38                 if(trefer.containsKey(tmp))
            39                     trefer.put(tmp, trefer.get(tmp)+1);
            40                 else
            41                     trefer.put(tmp, 1);
            42             }
            43             for(Map.Entry<Integer, Integer> p:trefer.entrySet())
            44             {
            45                 String tstr=Integer.toBinaryString(p.getKey());
            46                 while(tstr.length()<len) tstr='0'+tstr;
            47                 if(refer.containsKey(p.getValue()))
            48                     refer.get(p.getValue()).add(tstr);
            49                 else
            50                 {
            51                     ArrayList<String> ttt=new ArrayList<String>();
            52                     ttt.add(tstr);
            53                     refer.put(p.getValue(), ttt);
            54                 }
            55                 
            56             }
            57             while(refer.size()>n) refer.remove(refer.lastKey());        
            58         }
            59         while(refer.size()>n) refer.remove(refer.lastKey());    
            60         for(Map.Entry<Integer,ArrayList<String> >p:refer.entrySet())
            61         {
            62             Collections.sort(p.getValue(),new cmp());
            63             System.out.print(p.getKey());
            64             for(String i:p.getValue())
            65                 System.out.print(" "+i);
            66             System.out.println();
            67             
            68         }
            69 
            70     }
            71 
            72 }
            73 


            posted on 2010-10-15 23:15 yzhw 閱讀(109) 評論(0)  編輯 收藏 引用 所屬分類: data struct

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

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久精品国产亚洲av水果派| 午夜视频久久久久一区| 狠狠色丁香久久综合五月| 热久久国产精品| 久久免费看黄a级毛片| 91精品国产综合久久精品| 久久久久久av无码免费看大片| 日韩精品久久无码人妻中文字幕| 伊人久久精品线影院| 亚洲精品午夜国产VA久久成人| 91精品国产91热久久久久福利| 亚洲国产另类久久久精品| 久久涩综合| 久久精品国产亚洲精品| 久久精品国产影库免费看 | 精品久久久久久久久久中文字幕| 中文字幕日本人妻久久久免费| 日批日出水久久亚洲精品tv| 久久99精品国产一区二区三区 | 91精品国产综合久久精品| 久久久久亚洲AV无码观看| 香蕉99久久国产综合精品宅男自 | 九九精品99久久久香蕉| 久久亚洲AV成人无码| 久久亚洲国产精品五月天婷| 夜夜亚洲天天久久| 欧美精品一本久久男人的天堂| 伊人久久大香线蕉亚洲| 久久精品国产亚洲AV忘忧草18| 亚洲精品美女久久久久99小说| 久久91精品综合国产首页| 99精品久久久久久久婷婷| 国产日韩久久免费影院 | 2019久久久高清456| 一级做a爰片久久毛片看看| 香蕉久久久久久狠狠色| 亚洲国产香蕉人人爽成AV片久久| 久久伊人精品青青草原日本| 日韩中文久久| 色诱久久久久综合网ywww | 狠狠88综合久久久久综合网 |