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

            coreBugZJ

            此 blog 已棄。

            EOJ 2069 Asteroids

             1/*
             2EOJ 2069 Asteroids
             3
             4
             5----問題描述:
             6
             7Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500).
             8The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid.
             9
            10Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.
            11This weapon is quite expensive, so she wishes to use it sparingly.
            12Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.
            13
            14
            15----輸入:
            16
            17* Line 1: Two integers N and K, separated by a single space.
            18* Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.
            19
            20
            21----輸出:
            22* Line 1: The integer representing the minimum number of times Bessie must shoot.
            23
            24
            25----樣例輸入:
            26
            273 4
            281 1
            291 3
            302 2
            313 2
            32
            33
            34----樣例輸出:
            35
            362
            37
            38
            39----分析:
            40
            41建立二分圖模型,
            42若第 i 行和第 j 列處存在一個 asteroid ,則 x[i] 與 y[j] 連一條邊,
            43求二分圖最大匹配,使用匈牙利算法。
            44
            45*/

            46
            47
            48#include <stdio.h>
            49#include <string.h>
            50
            51#define  L  503
            52
            53int adj[ L ][ L ], n, state[ L ], result[ L ];
            54
            55int find( int i ) {
            56        int j, k;
            57        for ( j = adj[ i ][ 0 ]; j > 0--j ) {
            58                k = adj[ i ][ j ];
            59                if ( state[ k ] == 0 ) {
            60                        state[ k ] = 1;
            61                        if ( ( result[ k ] == 0 ) || find( result[ k ] ) ) {
            62                                result[ k ] = i;
            63                                return 1;
            64                        }

            65                }

            66        }

            67        return 0;
            68}

            69
            70int maxMatch() {
            71        int ans = 0, i;
            72        for ( i = 1; i <= n; ++i ) {
            73                memset( state, 0sizeof( state ) );
            74                if ( find( i ) )
            75                        ++ans;
            76        }

            77        return ans;
            78}

            79
            80int main() {
            81        int i, j, k;
            82        memset( adj, 0sizeof( adj ) );
            83        memset( result, 0sizeof( result ) );
            84        scanf( "%d%d"&n, &k );
            85        while ( k-- ) {
            86                scanf( "%d%d"&i, &j );
            87                adj[ i ][ ++adj[ i ][ 0 ] ] = j;
            88        }

            89        printf( "%d\n", maxMatch() );
            90        return 0;
            91}

            92

            posted on 2012-03-30 22:18 coreBugZJ 閱讀(524) 評論(0)  編輯 收藏 引用 所屬分類: ACMAlgorithm課內作業

            国产成人99久久亚洲综合精品| 国产亚洲成人久久| 人人狠狠综合久久亚洲婷婷| 国产精品一久久香蕉国产线看| 国产精品久久久久无码av| 久久免费国产精品一区二区| 精品乱码久久久久久夜夜嗨 | 久久99精品国产| 精品国产一区二区三区久久蜜臀| 中文字幕久久亚洲一区| 国产精品99精品久久免费| 久久久久无码中| 国产精品一久久香蕉产线看| 青青草原综合久久大伊人| 久久中文娱乐网| 久久夜色精品国产噜噜噜亚洲AV| 品成人欧美大片久久国产欧美...| 伊人久久精品无码二区麻豆| 99热都是精品久久久久久| 男女久久久国产一区二区三区| 国产精品久久久99| 久久亚洲精品视频| 国内精品久久人妻互换| 久久夜色精品国产亚洲| 欧美激情精品久久久久久久九九九| 婷婷久久久亚洲欧洲日产国码AV | 久久99精品久久久久久秒播 | 人妻精品久久久久中文字幕69 | 久久午夜夜伦鲁鲁片免费无码影视| www.久久热.com| 国产情侣久久久久aⅴ免费| 亚洲国产精品一区二区久久hs| 久久亚洲日韩看片无码| 久久国产欧美日韩精品| 久久福利资源国产精品999| 精品一久久香蕉国产线看播放| 久久综合九色综合97_久久久| 国产精品久久久久久福利69堂| 国产精品久久自在自线观看| 91精品国产色综合久久| 四虎国产精品免费久久5151 |