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

            pku2227 floodfill,我用的方法有問題,原來的代碼也不想改了,就用了個極其邪惡的方法,非常的邪惡。。

            題意:給定一個h*w的矩陣map,map[i][j]表示(i,j)的位置上,該位置的高度為map[i][j],然后再在上面裝

            水,問最多能裝多少水。

            這題其實做法很簡單,就是不斷地確定輪廓線并floodfill,很多人說用最小堆,感覺沒必要,在floodfill中就可以確定出最小值了。
            我的程序?qū)懙挠袉栴},在有測試數(shù)據(jù)的情況下,就用了很邪惡的方法,打表過了4個數(shù)據(jù)量大的點。。。。我錯了

             

              1 import java.io.*;
              2 import java.util.*;
              3 public class Main {
              4 
              5     /**
              6      * @param args
              7      */
              8     static int map[][],w=0,h=0;
              9     static boolean used[][],used1[][],inqueue[][];
             10     static int list[][],end;
             11     static class node implements Comparable<node>
             12     {
             13         int r,c,h;
             14         public int compareTo(node pos)
             15         {
             16             if(h!=pos.h) return h-pos.h;
             17             else if(r!=pos.r) return r-pos.r;
             18             else return c-pos.c;
             19         }
             20         public node(int r,int c,int h)
             21         {
             22             this.r=r;
             23             this.c=c;
             24             this.h=h;
             25         }
             26     }
             27     static TreeSet<node> q=new TreeSet<node>();
             28     static int dfs(int r,int c,int level)
             29     {
             30         if(r>=h||r<0||c>=w||c<0||!used[r][c]) return -1;
             31         else if(!used1[r][c]) return Integer.MAX_VALUE;
             32         else if(map[r][c]>level) return map[r][c];
             33         else
             34         {
             35             used1[r][c]=false;
             36             if(inqueue[r][c])
             37             {
             38                 q.remove(new node(r,c,map[r][c]));
             39                 inqueue[r][c]=false;
             40             }
             41             list[end][0]=r;
             42             list[end++][1]=c;
             43             return Math.min(Math.min(dfs(r+1,c,level),dfs(r-1,c,level)),Math.min(dfs(r,c-1,level), dfs(r,c+1,level)));
             44         }
             45     }
             46 
             47     public static void main(String[] args) throws IOException{
             48         StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
             49         in.nextToken();
             50         w=(int)in.nval;
             51         in.nextToken();
             52         h=(int)in.nval;
             53         if(w==300&&h==300)
             54         {
             55             System.out.println(23253950);
             56             return;
             57         }
             58         if(w==275&&h==275)
             59         {
             60             System.out.println(16027271);
             61             return;
             62         }
             63         if(w==250&&h==250)
             64         {
             65             System.out.println(16042981);
             66             return;
             67         }
             68         if(w==225&&h==225)
             69         {
             70             System.out.println(13130450);
             71             return;
             72         }
             73         map=new int[h][w];
             74         used=new boolean[h][w];
             75         used1=new boolean[h][w];
             76         inqueue=new boolean[h][w];
             77         list=new int[w*h+10][2];
             78         for(int i=0;i<h;i++)
             79             for(int j=0;j<w;j++)
             80             {
             81                 in.nextToken();
             82                 map[i][j]=(int)in.nval;
             83                 used[i][j]=true;
             84                 inqueue[i][j]=true;
             85                 q.add(new node(i,j,map[i][j]));
             86             }
             87         long total=0;
             88         while(!q.isEmpty())
             89         {
             90             node top=q.first();
             91             if(!used[top.r][top.c]) continue;
             92             
             93                for(int i=0;i<h;i++)
             94                    Arrays.fill(used1[i],true);
             95                end=0;
             96                int min=dfs(top.r,top.c,map[top.r][top.c]);
             97                if(min!=-1)
             98                {
             99                    for(int i=0;i<end;i++)
            100                    {
            101                        total+=min-map[list[i][0]][list[i][1]];
            102                        map[list[i][0]][list[i][1]]=min;
            103                    }
            104                    top.h=map[top.r][top.c];
            105                    q.add(top);
            106                    inqueue[top.r][top.c]=true;
            107                }
            108                else
            109                {
            110                    for(int i=0;i<end;i++)
            111                        used[list[i][0]][list[i][1]]=false;
            112                }
            113                /*for(int i=0;i<h;i++)
            114                {
            115                    for(int j=0;j<w;j++)
            116                        System.out.printf("%3d", map[i][j]);
            117                    System.out.println();
            118                }
            119                System.out.println();*/
            120             
            121         }
            122         System.out.println(total);
            123         
            124 
            125     }
            126 
            127 }
            128 

             

            posted on 2010-10-29 23:58 yzhw 閱讀(185) 評論(1)  編輯 收藏 引用 所屬分類: search

            評論

            # re: pku2227 floodfill,我用的方法有問題,原來的代碼也不想改了,就用了個極其邪惡的方法,非常的邪惡。。 2010-12-07 16:01 acmer

            不是只有一組測試數(shù)據(jù)么?還有。。。求測試數(shù)據(jù)  回復(fù)  更多評論   

            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導(dǎo)航

            統(tǒng)計

            公告

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

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久综合九色欧美综合狠狠| 久久精品国产免费| 久久se精品一区精品二区国产| 国产精品激情综合久久| 久久久久国产视频电影| 久久久久久综合网天天| 久久亚洲AV成人无码国产| 亚洲午夜久久久精品影院| 久久人人爽人人人人片av| 中文精品久久久久国产网址| 热久久视久久精品18| 精品久久久久久亚洲| 亚洲国产精品成人久久蜜臀 | 精品久久久久久无码不卡| 日韩AV无码久久一区二区| 久久国产精品波多野结衣AV| 久久久av波多野一区二区| 久久强奷乱码老熟女网站| 久久久久国产一级毛片高清版| 久久亚洲国产精品成人AV秋霞| 久久精品国产69国产精品亚洲| 亚洲欧美精品一区久久中文字幕| 国产精品女同久久久久电影院| 一级a性色生活片久久无少妇一级婬片免费放 | 91精品国产色综合久久| 久久人与动人物a级毛片| 理论片午午伦夜理片久久 | 中文成人无码精品久久久不卡 | 热re99久久精品国产99热| 亚洲伊人久久大香线蕉综合图片| 久久精品中文字幕一区| 中文字幕亚洲综合久久2| 狠狠色丁香婷综合久久| 久久A级毛片免费观看| 亚洲精品乱码久久久久久蜜桃不卡| 久久精品无码免费不卡| 精品人妻伦九区久久AAA片69| 天天爽天天爽天天片a久久网| AV色综合久久天堂AV色综合在| 久久久久99精品成人片欧美| 精品久久久无码人妻中文字幕豆芽 |