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 ...
随机推荐
- git checkout 命令详解(转)
在日常的git操作中,git checkout——检出,是我们的常用命令.最为常用的两种情形是创建分支和切换分支. 在下面的命令中,使用了一些简写,在这里说明一下: git st # git stat ...
- Dubbo与Zookeeper、SpringMVC整合和利用(负载均衡、容错)
互联网发展,扩大了网站应用程序的大小.传统的垂直应用架构已经无法应付.分布式服务架构和流量计算架构势在必行,Dubbo是一个分布式服务框架.在这样的情况下诞生的.如今核心业务抽取出来.作为独立的服务, ...
- HTTP必知必会(转)
HTTP协议作为网络传输的基本协议,有着广泛的应用.HTTP协议的完整内容很多,但是其核心知识却又简单精炼.学习者应该掌握其基本结构,并且能够举一反三.这篇文章所列的,就是在实际开发中必须知道必须掌握 ...
- 一个用于每一天JavaScript示例-SVG中间javaScript画廊
<?xml version="1.0" standalone="no"? > <!DOCTYPE svg PUBLIC "-//W3 ...
- js之面向对象----封装篇
学习了一天的面向对象总结一下,共分为三类 - -! 老规矩 第一部分是概念性知识!!! 面向对象编程,我们可以把他想象成我们在造人.一个对象便是一个人,这个人有胳膊有腿,这便是一个对象的属性或者方法. ...
- NYNU_省赛选拔题(6)
题目描述 有一天,小米找到了一个藏宝的迷宫地图,迷宫在一个沙漠里有,迷宫里面有许多宝藏.迷宫里可能有N个藏宝地点,用1到K标记.藏宝地点之间最多有一条通路相连.标记1为迷宫的进出口. 他已经知道其中K ...
- bigdata_ambari修改hiveserver_metastore链接库(从0.14 升级到1.2.1 )
第一步:[db升级 ,先看第二步] cd到 hive的 metastore upgrade目录 cd /usr/hdp/2.5.0.0-1245/hive/scripts/metastore/upg ...
- 【从翻译mos文章】oracle linux 和外部存储系统 关系
oracle linux 和外部存储系统 关系 参考原始: Oracle Linux and External Storage Systems (Doc ID 753050.1) 范围: Linux ...
- linux_环境变量设置 utf-8
echo $LANG 显示编码 : en_US.UTF-8 英文urf8有时显示程序输出是? 解决方法: vim ~/.bashrc 最后一行追加: export LANG=zh_CN.UTF- ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...