Strategic Game HDU
Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3772 Accepted Submission(s): 1663
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:
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 <stdio.h>
#include <string.h>
#define CL(x,v);memset(x,v,sizeof(x)); const int maxn = 1500 + 10;
int n,top,link[maxn];
bool used[maxn];
int next[maxn*maxn],head[maxn*maxn],num[maxn*maxn]; int Find(int u)
{
for(int i = head[u];i != -1;i = next[i])
{
int v = num[i];
if(!used[v])
{
used[v] = u;
if(link[v] == -1||Find(link[v]))
{
link[v] = u;
return 1;
}
}
}
return 0;
} int KM()
{
int res = 0;
CL(link,-1);
for(int u = 0;u < n;u++)
{
CL(used,0);
res += Find(u);
}
return res;
} int main()
{
int m,i,j,index,vex;
while(~scanf("%d",&n))
{
top = 0;
CL(head,-1);
for(i = 0;i < n;i++)
{
scanf("%d:(%d)",&index,&m);
for(j = 0;j < m;j++)
{
scanf("%d",&vex);
next[top] = head[index];
num[top] = vex;
head[index] = top++;
next[top] = head[vex];
num[top] = index;
head[vex] = top++;
}
}
printf("%d\n",KM()/2);
}
return 0;
}
Strategic Game HDU的更多相关文章
- I - Strategic Game - hdu 1054(最小点覆盖)
题意:用最小的点来覆盖全部的边,因为二分图里面最大的匹配就是最小覆盖,所以直接匹配一下即可 ****************************************************** ...
- Strategic Game HDU - 1054(最小顶点覆盖)
最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联: ...以为自己很聪明..用边连边...最后还是点连点 哎.... hc 写的 匈牙利足够///// #include <iostr ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
- HDU——T 1054 Strategic Game
http://acm.hdu.edu.cn/showproblem.php?pid=1054 Time Limit: 20000/10000 MS (Java/Others) Memory Li ...
- HDU 1054:Strategic Game
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (hdu step 6.3.1)Strategic Game(求用最少顶点数把全部边都覆盖,使用的是邻接表)
题目: Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1054 Strategic Game(树形DP)
Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he ...
随机推荐
- dp related problems (update continuously)
Leetcode Maximum Product Subarray 这个问题是说给一个整数数组.求最大连续子阵列产品. 纠结了包括阵列中的很长一段时间0而如何处理负数,关键的事实是,负治疗,所以我们录 ...
- 使用Enterprise Architecture绘制10种UML画画
UML绘制10种课程要求UML画画,选Enterprise Architecture作为一个绘图工具,每一个草图必须是网上找教程,我觉得很麻烦,还有一些数字并没有找到详细的教程.在我自己找一个绘图方法 ...
- 基于注释配置bean和装饰bean
1.组件扫描 Spring容器能够从classpath(类路径)下自动扫描.侦测和实例化具有特定注释的组件. 2.特定注释组件 –@Component: 基本注解, 标识了一个受 Spring 管理的 ...
- SSIS从理论到实战,再到应用(6)----SSIS的自带日志功能
原文:SSIS从理论到实战,再到应用(6)----SSIS的自带日志功能 上期回顾: SSIS从理论到实战,再到应用(5)----流程控制之Foreach循环 博主最近新负责了一个ssis大项目的架构 ...
- java安全编程
java安全程序实际上是一个点稍微防御性编程意味着内,竟java作为编程语言,较C,c++,本身被认为是比较安全的,随着C,C++这样的偏底层的编程语言比,java少了显示的指针调用.少了程序上的内存 ...
- 网络资源(8) - JAX-RS视频
2014_08_25 http://v.youku.com/v_show/id_XNjAzMzA4MTY0.html JAX-RS 2.0 RESTful Java on Steroids, by A ...
- Java串口通信详细解释
前言 说到开源.恐怕非常少有人不挑大指称赞. 学生通过开源码学到了知识,程序猿通过开源类库获得了别人的成功经验及可以按时完毕手头的project,商家通过开源软件赚到了钱……,总之是皆大欢喜. 然而开 ...
- 《STL源代码分析》---stl_list.h读书笔记
STL在列表list它是一种经常使用的容器.list不连续双向链表在内存,而且是环形. 理解列表如何操作的详细信息,然后.阅读STL名单上的代码是最好的方法. G++ 2.91.57.cygnus\c ...
- 解决:<net.sf.ehcache.util.UpdateChecker> : New update(s) found: 2.6.5
由于该项目采用ehcache,所以tomcat每次登录你开始打印net.sf.ehcache.util.UpdateChecker doCheck 一旦有没有特别关注.从今天开始 Tomcat 什么时 ...
- 使用excel微调button调整日期
笔者:iamlaosong excel提供了一个调整的数字button.用来调节单元格增加或减少数量.因为它需要值是0-30000.所以不能直接用其调节日期.但能够使用"初始日期+调节值&q ...