博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1054 Strategic Game (二分匹配)
阅读量:6073 次
发布时间:2019-06-20

本文共 2468 字,大约阅读时间需要 8 分钟。

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 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 form a tree. He has to put the 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:
 

 

Sample Input
4
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)
 

 

Sample Output
1
2
 

 

Source
 

 

Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 

 题意:求最少要多少个士兵站岗可使全部点都能观察得到。

         因为是树形结构,每个点都会有一条边,最大匹配数即为题解(不证明了..)。

         和 hdu1068 差不多,一样的模板,不过这题是求最大匹配数,匈牙利后结果除二即为解。

 

1 //234MS    280K    1166 B    C++ 2 #include
3 #include
4 #define N 1505 5 struct node{ 6 int v; 7 int next; 8 }edge[10*N]; 9 int match[N];10 int vis[N];11 int head[N];12 int n,edgenum;13 void addedge(int u,int v)14 {15 edge[edgenum].v=v;16 edge[edgenum].next=head[u];17 head[u]=edgenum++;18 }19 int dfs(int x)20 {21 for(int i=head[x];i!=-1;i=edge[i].next){22 int v=edge[i].v;23 if(!vis[v]){24 vis[v]=1;25 if(match[v]==-1 || dfs(match[v])){26 match[v]=x;27 return 1;28 }29 }30 }31 return 0;32 }33 int hungary()34 {35 int ret=0;36 memset(match,-1,sizeof(match));37 for(int i=0;i

 

转载于:https://www.cnblogs.com/GO-NO-1/p/3745920.html

你可能感兴趣的文章
sql 字符串操作
查看>>
【转】Android布局优化之ViewStub
查看>>
网络安全管理技术作业-SNMP实验报告
查看>>
根据Uri获取文件的绝对路径
查看>>
Flutter 插件开发:以微信SDK为例
查看>>
.NET[C#]中NullReferenceException(未将对象引用到实例)是什么问题?如何修复处理?...
查看>>
边缘控制平面Ambassador全解读
查看>>
Windows Phone 7 利用计时器DispatcherTimer创建时钟
查看>>
程序员最喜爱的12个Android应用开发框架二(转)
查看>>
vim学习与理解
查看>>
DIRECTSHOW在VS2005中PVOID64问题和配置问题
查看>>
MapReduce的模式,算法以及用例
查看>>
《Advanced Linux Programming》读书笔记(1)
查看>>
zabbix agent item
查看>>
一步一步学习SignalR进行实时通信_7_非代理
查看>>
AOL重组为两大业务部门 全球裁员500人
查看>>
字符设备与块设备的区别
查看>>
为什么我弃用GNOME转向KDE(2)
查看>>
Redis学习记录初篇
查看>>
爬虫案例若干-爬取CSDN博文,糗事百科段子以及淘宝的图片
查看>>