Strategic Game

                                                        Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
                                                        Total Submission(s): 3772    Accepted Submission(s): 1663

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
 
 
 
 
题意:
            
一道很明了的二分匹配图的最小点覆盖问题;
         最小点覆盖 == 最大匹配数;    想知道为什么的话,可以看一下我学长的博客:链接地址
        题目意思就不啰嗦了,自己看吧。要注意的就是,该题是一个双向图,所以结果要除以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的更多相关文章

  1. I - Strategic Game - hdu 1054(最小点覆盖)

    题意:用最小的点来覆盖全部的边,因为二分图里面最大的匹配就是最小覆盖,所以直接匹配一下即可 ****************************************************** ...

  2. Strategic Game HDU - 1054(最小顶点覆盖)

    最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联: ...以为自己很聪明..用边连边...最后还是点连点  哎.... hc 写的  匈牙利足够///// #include <iostr ...

  3. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  4. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  5. ACM--[kuangbin带你飞]--专题1-23

    专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...

  6. HDU——T 1054 Strategic Game

    http://acm.hdu.edu.cn/showproblem.php?pid=1054 Time Limit: 20000/10000 MS (Java/Others)    Memory Li ...

  7. HDU 1054:Strategic Game

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

  8. (hdu step 6.3.1)Strategic Game(求用最少顶点数把全部边都覆盖,使用的是邻接表)

    题目: Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU 1054 Strategic Game(树形DP)

    Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he ...

随机推荐

  1. UNIX网络编程卷1 server编程范式0 迭代server

    本文senlie原版的.转载请保留此地址:http://blog.csdn.net/zhengsenlie 1.迭代 TCP server总是在全然处理某个客户的请求后才转向下一个客户. 2.从进程控 ...

  2. HDU1068/POJ1466_Girls and Boys(二分图/最大独立集=N-最大匹配)

    解题报告 http://blog.csdn.net/juncoder/article/details/38160591 题目传送门(POJ) 题目传送门(HDU) 题意: 求满足条件的最大集合:集合内 ...

  3. 微信JS-SDK“分享信息设置”API及数字签名生成方法(NodeJS版本)

    原文:微信JS-SDK"分享信息设置"API及数字签名生成方法(NodeJS版本) 先上测试地址以示成功: 用微信打开下面地址测试 http://game.4gshu.com/de ...

  4. UIBarButtonItem 小记边

     watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWFuZ3poZW4xOTkwMDcwMQ==/font/5a6L5L2T/fontsize/400/ ...

  5. hdu 2066 一个人的旅行 最短路径

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. 大话设计模式C++达到-文章16章-国家模式

    一.UML画画 二.概念 状态模式(State):当一个对象的内在状态改变时同意改变其行为.这个对象看起来像是改变了其类. 三.说明 以下是来自书本和网络的对状态模式的定义和分析: (1)状态模式同意 ...

  7. set RowCount 与 top n

    有时,采用top n中间n它是一个变量,这将需要使用()去完成: declare @count1 int set @count1 = 8 select top <strong>(@coun ...

  8. E: 无法获取锁 /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)解决方法

    /*********************************************************************  * Author  : Samson  * Date   ...

  9. Oracle 免费的数据库

    Oracle 免费的数据库--Database 快捷版 11g 安装使用与"SOD框架"对Oracle的CodeFirst支持 一.Oracle XE 数据库与连接工具安装使用 O ...

  10. 所谓策略,我站在旁边看今天 神刻的样子O2O

    雕爷.何许人也? 卖牛腩的大叔? 卖精油的大爷?还是卖烤肉的家伙? 事实上以上答案都是肯定的,他就是阿芙精油,雕爷牛腩创业神话的缔造者.那么雕爷是怎样取得这种创业成功的呢?前段时间我还不清楚雕爷的厉害 ...