Hdu1054 Strategic Game(最小覆盖点集)
Strategic Game
minimum number of soldiers on the nodes so that they can observe all the edges. Can you help him?
Your program should find the minimum number of soldiers that Bob has to put for a given tree.
The input file contains several data sets in text format. Each data set represents a tree with the following description:
the number of nodes
the description of each node in the following format
node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifier
or
node_identifier:(0)
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500). Every edge appears only once in the input data.
For example for the tree:
the solution is one soldier ( at the node 1).
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers). An example is given in the following table:
0:(1) 1
1:(2) 2 3
2:(0)
3:(0)
5
3:(3) 1 4 2
1:(1) 0
2:(0)
0:(0)
4:(0)
2
————————————————————————————————
题目的意思是给出一棵树,在顶点上放置士兵,使得每条边至少有一个顶点有士兵
思路:即求最小覆盖点集,根据最小覆盖点集=最大二分匹配,求出最大二分匹配即可
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=2000;
int uN,vN; //u,v数目
vector<int>g[MAXN];
int linker[MAXN];
bool used[MAXN]; bool dfs(int u)
{
int v;
int siz=g[u].size();
for(v=0; v<siz; v++)
if(!used[g[u][v]])
{
used[g[u][v]]=true;
if(linker[g[u][v]]==-1||dfs(linker[g[u][v]]))
{
linker[g[u][v]]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int n,m,x,y;
while(~scanf("%d",&n))
{
for(int i=0;i<MAXN;i++)
g[i].clear();
for(int i=0;i<n;i++)
{
scanf("%d:(%d)",&x,&m);
for(int j=0;j<m;j++)
{
scanf("%d",&y);
g[x].push_back(y);
g[y].push_back(x);
}
}
uN=vN=n;
printf("%d\n",hungary()/2); }
return 0;
}
Hdu1054 Strategic Game(最小覆盖点集)的更多相关文章
- hdu---(1054)Strategic Game(最小覆盖边)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ 1325 ZOJ 1364 最小覆盖点集
题意:有A,B两台机器, 机器A 有 n个模式(0, 1, 2....n-1),同样机器B有m个模式, 两个机器一开始的模式都为0,有k个作业(id,x,y) 表示作业编号id, 该作业必须在A机器在 ...
- hdu 1150 Machine Schedule 最小覆盖点集
题意:x,y两台机器各在一边,分别有模式x0 x1 x2 ... xn, y0 y1 y2 ... ym, 现在对给定K个任务,每个任务可以用xi模式或者yj模式完成,同时变换一次模式需要重新启动一次 ...
- POJ3041轰炸行星(匈牙利算法 最小覆盖点集)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25232 Accepted: 13625 Descr ...
- HDU1054 Strategic Game —— 最小点覆盖 or 树形DP
题目链接:https://vjudge.net/problem/HDU-1054 Strategic Game Time Limit: 20000/10000 MS (Java/Others) ...
- HDU1054 Strategic Game——匈牙利算法
Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...
- HDU1054 Strategic Game(最小点覆盖)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu1054 Strategic Game 树形DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 思路:树形DP,用二分匹配也能解决 定义dp[root][1],表示以root 为根结点的子树且 ...
- HDU 1054 Strategic Game 最小点覆盖
最小点覆盖概念:选取最小的点数覆盖二分图中的所有边. 最小点覆盖 = 最大匹配数. 证明:首先假设我们求的最大匹配数为m,那么最小点覆盖必然 >= m,因为仅仅是这m条边就至少需要m个点.然后 ...
随机推荐
- html 转化成 pdf
- 20172325 2018-2019-2 《Java程序设计》第五周学习总结
20172325 2018-2019-2 <Java程序设计>第五周学习总结 教材学习内容总结 本次学习第九章内容,主要学习查找和排序. 查找 查找的定义:是一个过程,即在某个项目组中寻找 ...
- mysql5.6改进子查询实测试
表t1,t2 各自生成100万条记录. 表引擎 myiasm ,查询语句 select * from t1 where id2 in (select id2 from t2 ) 查询速度 2.x秒 ...
- 超详细的PS抠图方法
步骤: 1.打开图片,根据图片的特点选择抠图工具: 2.在图像上找到第一个定点,要求定点要完全暴露在画布中,并且是清晰可见的顶点: 3.抠取图像时,多边形套索的定点以及边线应该向内1-2个像素,为了避 ...
- Java Swing 中使用 EventQueue
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { ...
- SVN 钩子 同步测试服务器
http://blog.csdn.net/showso2006/article/details/6750441 多人开始使用subversion之后,就想着,要建立一个测试用的服务器,不需要把文件up ...
- 用php把access数据库导入到mysql
<?php header("content-Type: text/html; charset=utf-8"); /// ///把access数据库转换成mysql的SQL语句 ...
- JavaScript中hasOwnProperty函数
JavaScript中hasOwnProperty函数方法是返回一个布尔值,指出一个对象是否具有指定名称的属性. 使用方法: object.hasOwnProperty(proName) 其中参数 ...
- 【Java】生成图形验证码
本章介绍一个能生成比较好看的图形验证码类 生成验证码工具类 package com.util; import java.awt.Color; import java.awt.Font; import ...
- HDU 6129 Just do it
题意:给你一个包含n个数的序列A和一个数m,序列B中的数是序列A经过异或得到的,比如:b[i]=a[1]^a[2]^…..^a[i].现在让你求经过m次异或后,序列B的值. 思路:这题其实和杨辉三角 ...