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 ...
随机推荐
- HDOJ 3966 Aragorn's Story
树链拆分+树阵 (进入坑....) Aragorn's Story Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/327 ...
- 【DataStructure】Some useful methods for arrays
Last night it took me about two hours to learn arrays. For the sake of less time, I did not put emph ...
- Php面向对象 – 继承和重写
Php面向对象 – 继承和重写 承受: php于,通过类.使用特殊的经营宗旨. 通过定义类,采用extends来表示当前的类对象继承该类的对象. 样例: class C { public $p_c ...
- malloc,free简单的实现
有关标准库首先简要malloc其原理: 标准库内部通过一个双向链表.管理在堆中动态分配的内存. malloc函数分配内存时会附加若干(一般是12个)字节,存放控制信息. 该信息 ...
- JQUERY 选择
jQuery 选择器 jQuery 采用 CSS 一个选择选择 HTML 元素. $("p") 选取 <p> 元素. $("p.intro") 选取 ...
- java保存获取Web内容的文件
package com.mkyong; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.F ...
- 【网络流量-二部图最大匹配】poj3041Asteroids
/* 这个问题将是每行一个x作为节点x,没有列y作为节点y,障碍物的坐标xy来自x至y的 边缘.图建的问题后,变成,拿得最少的点,因此,所有这些点与相邻边缘,即最小 点覆盖,与匈牙利算法来解决. -- ...
- POJ 1664 把苹果
把苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25785 Accepted: 16403 Descript ...
- CSS_img标签usemap属性图片中选择区域加入超链接
例子: <IMG usemap="#Map" alt="" src="/images/banbian.jpg"> <map ...
- STL慎重选择删除元素的
一.要删除容器中有特定值的全部对象 1.假设容器是vector.string或deque.则使用erase-remove习惯使用方法.比如: vector<int> c; c.era ...