• HDU 1054 Strategic Game


    Strategic Game

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


    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:  1068 1053 1150 1151 1281 
     
     
    二分图匹配  之  最小点覆盖
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 using namespace std;
     5 #define maxn  1510
     6 int n,head[maxn],tot,link[maxn];
     7 struct Edge{
     8     int from,to,next;
     9 }e[maxn*2];
    10 bool exist[maxn];
    11 void Add_Edge(int u,int v){
    12     e[++tot].from=u;e[tot].to=v;
    13     e[tot].next=head[u];head[u]=tot;
    14 }
    15 void Prepare(){
    16     memset(e,0,sizeof(e));tot=0;
    17     memset(head,0,sizeof(head));
    18     memset(link,-1,sizeof(link));
    19 }
    20 bool DFS(int u){
    21     for(int i=head[u];i;i=e[i].next){
    22         int v=e[i].to;
    23         if(!exist[v]){
    24             exist[v]=true;
    25             if(link[v]==-1 || DFS(link[v])){
    26                 link[v]=u;
    27                 return true;
    28             }
    29         }
    30     }
    31     return false;
    32 }
    33 int main()
    34 {
    35     while(scanf("%d",&n)==1){
    36         Prepare();
    37         for(int i=0,m,u,v;i<n;i++){
    38             scanf("%d:(%d)",&u,&m);
    39             for(int j=0;j<m;j++){
    40                 scanf("%d",&v);
    41                 Add_Edge(u,v);Add_Edge(v,u);
    42             }
    43         }
    44         int ans=0;
    45         for(int i=0;i<n;i++){
    46             memset(exist,false,sizeof(exist));
    47             if(DFS(i))ans++;
    48         }
    49         printf("%d
    ",ans/2);
    50     }
    51     return 0;
    52 }
  • 相关阅读:
    java 静态方法分析
    编译时常量与运行时常量
    springboot+elasticsearch配置实现
    spring+mybatise注解实现
    @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
    @RequestBody 的正确使用办法
    springboot+jps+druid项目搭建
    python 源码安装
    liunx 时间ntp同步服务器
    spring 定时任务corn表达式
  • 原文地址:https://www.cnblogs.com/suishiguang/p/6428870.html
Copyright © 2020-2023  润新知