Strategic Game

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

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
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1053 1151 1142 1233 1045 
 

问题描述
鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时候他无法快速找到解决方案,那么他很伤心。现在他有以下问题。他必须捍卫一座中世纪城市,其道路形成一棵树。他必须将最少数量的士兵放在节点上,以便他们可以观察所有的边缘。你的程序应该找到Bob给给定树的最小兵数。

思路:用最少的节点覆盖所有的边。最小点覆盖裸题=最大匹配数

这个题的数据比较大,用邻接表的话会T,用邻街链表的话可以A

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1500+10
using namespace std;
bool vis[N];
int n,m,k,x,y,tot,head[N],girl[N],map[N][N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
struct Edge
{
    int from,to,next;
}edge[N];
int add(int x,int y)
{
    tot++;
    edge[tot].to=y;
    edge[tot].next=head[x];
    head[x]=tot;
}
int find(int x)
{
    for(int i=head[x];i;i=edge[i].next)
    {
        int t=edge[i].to;
        if(!vis[t])
        {
            vis[t]=true;
            ||find(girl[t])) {girl[t]=x;;}
        }
    }
    ;
}
int main()
{
    ,sum,ans;
    while(scanf("%d",&n)!=EOF)
    {
        ans=,sum=;tot=;
        memset(map,,sizeof(map));
        memset(head,,sizeof(head));
        ;i<=n;i++)
        {
            x=read();m=read();
            ,y+),add(y+,x+);}
        }
        memset(girl,-,sizeof(girl));
        ;i<=n;i++)
        {
            memset(vis,,sizeof(vis));
            if(find(i)) ans++;
        }
        printf();
    }
    ;
}

HDU——1054 Strategic Game的更多相关文章

  1. HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)

    d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...

  2. HDU 1054 Strategic Game(最小路径覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因 ...

  3. HDU 1054:Strategic Game

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

  4. HDU 1054 Strategic Game(树形DP)

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

  5. HDU 1054 Strategic Game(树形DP)

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

  6. hdu 1054 Strategic Game 经典树形DP

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

  7. hdu 1054 Strategic Game (二分匹配)

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

  8. hdu 1054 Strategic Game(tree dp)

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

  9. hdu 1054 Strategic Game (简单树形DP)

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

随机推荐

  1. guanbi selinux

    编辑/etc/sysconfig/selinux,把第一条选项改为 disabled

  2. laravel的scout包安装及laravel-es包安装

    安装laravel/scout 作用:搜索驱动,可随时更换驱动,上层业务逻辑可不用改变 官网文档:https://laravel-china.org/docs/laravel/5.4/scout/12 ...

  3. iOS逆向实战与工具使用(微信添加好友自动确认)

    iOS逆向实战与工具使用(微信添加好友自动确认) 原文链接 源码地址 WeChatPlugin-iOS Mac OS 版微信小助手(远程控制.消息防撤回.自动回复.微信多开) 一.前言 本篇主要实现在 ...

  4. 图解GitHub

    转自:http://marklodato.github.io/visual-git-guide/index-zh-cn.html 个人觉得这一篇比一些入门教程更值得看,图解很详细到位,很容易理解其工作 ...

  5. 获取页面URL两种方式

    以请求http://localhost:8080/doctor/demo?code=1为例 一:用java代码获取 //获取URL中的请求参数.即?后的条件 code=1 String querySt ...

  6. [python3]PyCharm编辑器

    简介 Python有丰富的开发工具,本教程不一一进行介绍,只推荐大家使用PyCharm,因为python开发者都在用它,但缺点就是消耗电脑资源,如果你电脑配置低,就会比较卡 下载 下载地址: http ...

  7. Codeforces GYM 100741A . Queries

    time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output stan ...

  8. 51nod 1267 4个数和为0

    基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个整数,你来判断一下是否能够选出4个数,他们的和为0,可以则输出"Yes",否则输出&qu ...

  9. 云梯互联:所有主机已全面支持免费SSL!附小白配置教程。

    HTTPS和HTTP的区别:1.HTTPS是加密传输协议,HTTP是名文传输协议;2.HTTPS需要用到SSL证书,而HTTP不用;3.HTTPS比HTTP更加安全,对搜索引擎更友好,利于SEO4. ...

  10. 第二周作业xml学习情况

    1.xml简介 可扩展标记语言是一种很像超文本标记语言的标记语言. 它的设计宗旨是传输数据,而不是显示数据. 它的标签没有被预定义.您需要自行定义标签. 它被设计为具有自我描述性. 它是W3C的推荐标 ...