Air Raid---hdu1151(最小路径覆盖)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151

最小路径覆盖 == 顶点数 - 最大匹配。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 130

int maps[N][N], vis[N], used[N], n, m, ans;
bool Find(int u)
{
    for(int i=1; i<=n; i++)
    {
        if(!vis[i] && maps[u][i])
        {
            vis[i] = 1;
            if(!used[i] || Find(used[i]))
            {
                used[i] = u;
                return true;
            }
        }
    }
    return false;
}

int main()
{
    int T, x, y;
    scanf("%d", &T);
    while(T--)
    {
        memset(maps, 0, sizeof(maps));
        memset(used, 0, sizeof(used));
        scanf("%d%d", &n, &m);
        while(m--)
        {
            scanf("%d%d", &x, &y);
            maps[x][y] = 1;
        }
        ans=0;
        for(int i=1; i<=n; i++)
        {
            memset(vis, 0, sizeof(vis));
            if(Find(i))
                ans++;
        }
        printf("%d\n",n-ans);
    }
    return 0;
}
时间: 2024-10-18 18:56:36

Air Raid---hdu1151(最小路径覆盖)的相关文章

HDU 1151 Air Raid(最小路径覆盖 = 顶点数 - 最大匹配数)

Air Raid Problem Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you can never reach the same

hdu 1151 Air Raid (最小路径覆盖)

Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3085    Accepted Submission(s): 2004 Problem Description Consider a town where all the streets are one-way and each street leads from on

hdu 1151 Air Raid(二分图最小路径覆盖)

http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4029    Accepted Submission(s): 2675 Problem Description Consider a town where all the st

[HDOJ1151]Air Raid(最小路径覆盖,匈牙利算法)

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1151 题意:就是求最小路径覆盖,根据定义出的题. 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */

poj 1422 Air Raid (最小路径覆盖)

链接:poj 1422 题意:有n个点和m条有向边,现在要在点上放一些伞兵,伞兵可以沿着图走, 直到不能走为止,每条边有且仅有一个伞兵走过,问最少放多少个伞兵 思路:求的最小路径覆盖,用二分图来做 对于这样的一个有向图做最小路径覆盖,首先建图 然后每一条有向边对应左边的点指向右边的点 这样建好图之后求最大匹配数 最小路径覆盖=点数-最大匹配数 [cpp] view plaincopyprint? #include<stdio.h> #include<string.h> int n,

HDU 1151 Air Raid(最小路径覆盖)

二分图匹配(匈牙利算法的DFS实现) 初始化:g[][]两边顶点的划分情况 建立g[i][j]表示i->j的有向边就可以了,是左边向右边的匹配 g没有边相连则初始化为0 uN是匹配左边的顶点数,vN是匹配右边的顶点数 调用:res=hungary();输出最大匹配数 优点:适用于稠密图,DFS找增广路,实现简洁易于理解 时间复杂度:O(VE) ***************************************************************************/

HDU1151_Air Raid(二分图/最小路径覆盖=n-最大匹配)

解题报告 题目传送门 题意: 一个小镇,所有的街道都是单向的,这些街道都是从一个十字路口通往另一个十字路口,已知从任何十字路口出发,沿着这些街道行走,都不能回到同一个十字路口,也就是说不存在回路. 计算攻击这个小镇需要派的伞兵最少数目,这些伞兵要走遍小镇的所有十字路口,每个十字路口只由一个伞兵走到.每个伞兵在一个十字路口着陆,沿着街道可以走到其他十字路口. 思路: 用最小的伞兵覆盖街道,最小路径覆盖模型.把每个点拆成X1,Y1,这样建成二分图.最小路径覆盖=n-最大匹配数. #include <

hdu1151 最小路径覆盖

http://acm.hdu.edu.cn/showproblem.php?pid=1151 Problem Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town'

POJ 1422 Air Raid (二分图最小点集覆盖 匈牙利算法)

Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7236   Accepted: 4295 Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an i