博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Strategic Game(匈牙利算法,最小点覆盖数)
阅读量:6435 次
发布时间:2019-06-23

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

Strategic Game

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6421    Accepted Submission(s): 2987

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
题解:这个题意思是保卫城市,给一棵树,让求放几个士兵,可以看到所有的树的节点,二分匹配vec建图,最大匹配的值除以2就是答案;
代码:
#include
#include
#include
#include
#include
#include
#define mem(x,y) memset(x,y,sizeof(x))using namespace std;const int INF=0x3f3f3f3f;const int MAXN=1510;vector
vec[MAXN];int vis[MAXN],usd[MAXN];bool dfs(int u){ for(int i=0;i

 

转载地址:http://plqga.baihongyu.com/

你可能感兴趣的文章
android monkey
查看>>
Unity3D 人形血条制作小知识
查看>>
Delphi XE7中新并行库
查看>>
Java 调用Dll
查看>>
Java Servlet(三):Servlet中ServletConfig对象和ServletContext对象
查看>>
推荐系统多样性
查看>>
用BlazeMeter录制JMeter测试脚本
查看>>
通过PowerShell查询本机IP地址
查看>>
使用Dezender对zend加密后的php文件进行解密
查看>>
Nginx配置之基于域名的虚拟主机
查看>>
基于DDD的.NET开发框架 - ABP模块设计
查看>>
Linux下tar.xz结尾的文件的解压方法
查看>>
Redis 脚本
查看>>
【转载】我心目中最好的框架组合是
查看>>
项目代码规范
查看>>
解释型语言与编译型语言的区别
查看>>
Oracle 创建主键自增表
查看>>
Discovering versions from the identity service failed when creating the password plugin.
查看>>
C#设计模式——生成器模式(Builder Pattern)
查看>>
06-Java 本地文件操作
查看>>