zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    打印杨辉三角 --JS
    (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&lt;=3,输出剩下的人 )
    黑马day16 jquery&amp;属性过滤选择器
    JQuery学习(4-2-phpserver端1)
    微信企业号开发:启用回调模式
    Struts框架的国际化
    4、libgdx应用框架
    C++map类型 之 简单介绍
    图像处理与计算机视觉开源软件库及学习站点
    单例模式
  • 原文地址:https://www.cnblogs.com/suishiguang/p/6428870.html
Copyright © 2011-2022 走看看