Strategic Game HDU - 1054

#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
#define N 10100
int vis[N], h[N], used[N], maps[1510][1510], n, ans;
int e[N],ne[N],idx;
void add(int a, int b)
{
    e[idx]=b;
    ne[idx]=h[a];
    h[a]=idx++;
}
bool Find(int u)
{
    for(int j=h[u]; j!=-1; j=ne[j])
    {
        int v = e[j];
        if(!vis[v])
        {
            vis[v] = 1;
            if(!used[v] || Find(used[v]))
            {
                used[v] = u;
                return true;
            }
        }
    }
    return false;
}
int main()
{
    int a, b, m;
    while(scanf("%d", &n)!=EOF)
    {
        idx = 0;
        memset(h, -1, sizeof(h));
        for(int i=0; i<n; i++)
        {
            scanf("%d:(%d)", &a, &m);
            while(m--)
            {
                scanf("%d", &b);
                add(a, b);
                add(b, a);
            }
        }
        ans = 0;
        memset(used, 0, sizeof(used));
        for(int i=0; i<n; i++)
        {
            memset(vis, 0, sizeof(vis));
            if(Find(i))
                ans++;
        }
        printf("%d\n", ans/2);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12430949.html

时间: 2024-10-11 02:11:49

Strategic Game HDU - 1054的相关文章

I - Strategic Game - hdu 1054(最小点覆盖)

题意:用最小的点来覆盖全部的边,因为二分图里面最大的匹配就是最小覆盖,所以直接匹配一下即可 *********************************************************************** #include<stdio.h>#include<string.h>#include<queue>using namespace std; const int MAXN = 1505;const int oo = 1e9+7; stru

hdu 1054 Strategic Game (二分匹配)

Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4697    Accepted Submission(s): 2125 Problem Description Bob enjoys playing computer games, especially strategic games, but somet

hdu 1054 Strategic Game (最小顶点覆盖+稀疏图)

Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4889    Accepted Submission(s): 2225 Problem Description Bob enjoys playing computer games, especially strategic games, but some

hdu 1054 Strategic Game 二分图最小点覆盖

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题意: 给出一个无向图,求最小点覆盖. 思路: 用网络流来做设立一个超级源点和一个超级汇点. 每个点拆成i和i'. 从超级源点向点i连一条边,容量为1. 从i’向超级汇点连一条边,容量为1. 从i向i'连一条边,容量为正无穷. 然后求最小割/2.因为拆点拆成了2个. 也可以用二分图匹配来做,也是求出最大匹配然后/2. 1 #include <bits/stdc++.h> 2 using na

hdu - 1054 - Strategic Game(树形dp)

题意:一棵n个结点的无根树(0 < n <= 1500),在一个结点放一个士兵,可以守护与这个点相邻的所有边,问最少需要多少个士兵,可以守护所有边. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 -->>状态: dp[i][1]表示以 i 为结点的子树,在 i 放一个士兵,可以守护所有边的最少士兵数. dp[i][0]表示以 i 为结点的子树,在 i 不放士兵,可以守护所有边的最少士兵数. 状态转移方程(结点 j 是结点 i

HDU 1054 Strategic Game(树形DP)

Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which for

hdu 1054 Strategic Game 【匈牙利算法】

题目链接:http://acm.acmcoder.com/showproblem.php?pid=1054 题意:求无向图的最小顶点覆盖 = 最大匹配数 / 2; 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include <string> #include <functiona

HDU——1054 Strategic Game

Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8504    Accepted Submission(s): 4094 Problem Description Bob enjoys playing computer games, especially strategic games, but some

HDU 1054 Strategic Game(无向二分图的最大匹配)

( ̄▽ ̄)" //凡无向图,求匹配时都要除以2 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; const int MAXN=1505; int uN; vector<int> g[MAXN]; int link[MAXN]; bool vis[MAX