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

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            一本久久a久久精品vr综合| MM131亚洲国产美女久久| 久久综合亚洲色HEZYO国产| 亚洲精品第一综合99久久| 99久久无色码中文字幕人妻| 九九久久自然熟的香蕉图片| 久久精品一区二区| 久久精品人成免费| 亚洲精品乱码久久久久久中文字幕| 久久精品中文字幕久久| 久久99国产乱子伦精品免费| 亚洲∧v久久久无码精品| 99久久国产主播综合精品| 国产精品青草久久久久婷婷| 东方aⅴ免费观看久久av| 久久99九九国产免费看小说| 久久狠狠高潮亚洲精品| 亚洲AV乱码久久精品蜜桃| 国内精品久久国产| 少妇高潮惨叫久久久久久| 久久久久人妻精品一区| 婷婷五月深深久久精品| 久久精品国产精品亚洲精品| 香蕉久久夜色精品国产小说| 粉嫩小泬无遮挡久久久久久| 久久99精品久久久久久久不卡| 国产三级久久久精品麻豆三级| 久久久久成人精品无码中文字幕 | 久久91精品国产91久久户| 国产美女久久精品香蕉69| 精品一区二区久久| 热99RE久久精品这里都是精品免费| 欧美国产成人久久精品| 69久久夜色精品国产69| 久久精品国产精品亚洲人人| 香蕉久久夜色精品国产2020| 777久久精品一区二区三区无码| 热久久最新网站获取| 狠狠色综合久久久久尤物| 亚洲国产成人久久综合碰碰动漫3d | 亚洲伊人久久精品影院|