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

            oyjpArt ACM/ICPC算法程序設計空間

            // I am new in programming, welcome to my blog
            I am oyjpart(alpc12, 四城)
            posts - 224, comments - 694, trackbacks - 0, articles - 6

            RookAttack

            Posted on 2007-04-16 20:47 oyjpart 閱讀(974) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽

            Problem Statement

                 You have been given a rows-by-cols chessboard, with a list of squares cut out. The list of cutouts will be given in a String[] cutouts. Each element of cutouts is a comma-delimited lists of coords. Each coord has the form (quotes for clarity) "r c". If coord "r c" appears in an element of cutouts, it means that the square at row r column c (0-based) has been removed from the chessboard. This problem will involve placing rooks on a chessboard, so that they cannot attack each other. For a rook to attack a target piece, it must share the same row or column as the target. Your method will return an int that will be the maximum number of rooks that can be placed on the chessboard, such that no pair of rooks can attack each other. Rooks cannot be placed on cut out squares. The cut out squares do not affect where the rooks can attack.

            Constraints

            - rows will be between 1 and 300 inclusive.
            - cols will be between 1 and 300 inclusive.
            - cutouts will contain between 0 and 50 elements inclusive.
            - Each element of cutouts will contain between 3 and 50 characters inclusive.
            - Each element of cutouts will be a comma delimited list of coords. Each coord will be of the form "r c", where
            • r and c are integers, with no extra leading zeros,
            • r is between 0 and rows-1 inclusive,
            • and c is between 0 and cols-1 inclusive.
            - Each element of cutouts will not contain leading or trailing spaces.

            Examples

            1)
                
            2
            2
            {"0 0","0 1","1 1","1 0"}
            Returns: 0
            2)
                
            3
            3
            {"0 0","1 0","1 1","2 0","2 1","2 2"}
            Returns: 2

            看到這個題目有什么想法?
            8皇后問題相信是大家入門搜索或其他算法的經典教材了 如果被砍掉部分格子呢?
            看到row和col分別是300的時候相信想搜索的朋友們心里可能要嘀咕一下了

            如果這樣分析一下:
            由于在放置rook的時候要求這一行還有這一列一定只有這一個元素(注意是rook 不是queen 不要求斜行)
            也就是說一個rook可以唯一的決定一行和一列
            那么。。
            這個rook似乎可以看成是某一行和某一列的一條邊
            如果把rows作為一個集合 cols作為一個集合 把不是cut out的點作為row和col的連接
            于是就轉化成了:二分圖匹配
            按照最短路的增廣分析 時間復雜度不會超過o(n^3) 滿足題目要求
            比如一個3*3的棋盤 被cut out掉了(0,0) (1,2) (2,2) 3個格子
            row集合 0,1,2
            col集合 0,1,2
            可連接的邊為(0, 1), (0,2), (1, 0), (1,1), (2,0),(2,1)
            執行最大匹配 將會得到如下結果
            (0,2) (1,0), (2,1)
            滿足題意

            久久男人AV资源网站| 少妇高潮惨叫久久久久久| 久久国产视屏| 午夜天堂av天堂久久久| 2020久久精品国产免费| 国产精品免费久久久久影院| 久久精品国产AV一区二区三区| 麻豆精品久久精品色综合| 久久久久免费精品国产| 精品久久综合1区2区3区激情| 亚洲人成网亚洲欧洲无码久久| 嫩草影院久久国产精品| 色婷婷综合久久久久中文| 欧美午夜A∨大片久久| 狠狠狠色丁香婷婷综合久久俺| 亚洲精品乱码久久久久久不卡| 伊人久久大香线蕉精品| 精品久久久久久久无码| 亚洲中文字幕无码一久久区| 日韩va亚洲va欧美va久久| 99久久婷婷国产一区二区| 99久久人妻无码精品系列| 无码人妻精品一区二区三区久久| 欧美无乱码久久久免费午夜一区二区三区中文字幕| 久久综合给合久久狠狠狠97色69| 亚州日韩精品专区久久久| 久久人人爽人人爽人人片AV麻豆| 91超碰碰碰碰久久久久久综合| 久久777国产线看观看精品| 99精品国产在热久久无毒不卡| 久久久精品人妻一区二区三区四| 伊人久久大香线蕉av不卡| 无码人妻少妇久久中文字幕蜜桃 | 久久久久亚洲av无码专区 | 无码8090精品久久一区| 国内精品久久久久久中文字幕| www亚洲欲色成人久久精品| 国产99久久久国产精品~~牛| 国产—久久香蕉国产线看观看| 精品多毛少妇人妻AV免费久久| 久久综合久久鬼色|