HDU——1054 Strategic Game
Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8504 Accepted Submission(s): 4094
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
问题描述
鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时候他无法快速找到解决方案,那么他很伤心。现在他有以下问题。他必须捍卫一座中世纪城市,其道路形成一棵树。他必须将最少数量的士兵放在节点上,以便他们可以观察所有的边缘。你的程序应该找到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的更多相关文章
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- HDU 1054 Strategic Game(最小路径覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因 ...
- HDU 1054: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 ...
- HDU 1054 Strategic Game(树形DP)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game 经典树形DP
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game (二分匹配)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game(tree dp)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1054 Strategic Game (简单树形DP)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 《深入理解Java虚拟机》读书笔记
堆分配参数: -XX:+PrintGC 使用该参数,虚拟机启动后,只要遇到GC就会打印日志: -XX:+UseSerialGC 配置串行回收器: -XX:+PrintGCDeltails 可以查看详细 ...
- 解决jenkins插件列表为空的问题
可能是由于Jenkins的更新网站被QIANG,因此,请使用 http://mirror.xmission.com/jenkins/updates/update-center.json 来进行更新
- leetcode_919. Complete Binary Tree Inserter_完全二叉树插入
https://leetcode.com/problems/complete-binary-tree-inserter/ 给出树节点的定义和完全二叉树插入器类的定义,为这个类补全功能.完全二叉树的定义 ...
- 【整理】treeGrid 树形表格
treeGrid 树形表格 https://fly.layui.com/extend/treeGrid/
- 阿里云人脸比对API封装
这是根据封装是根据阿里云官方给的Demo进行修改的,当时是因为编写微信小程序云函数需要使用到阿里云人脸比对接口,才对其进行封装的. 记录下来,方便下次使用. 复制下来可以直接使用. 用到的依赖如下: ...
- selective_search_rcnn.m中代码
im = imresize(im, [NaN im_width]):把图像转换为宽度为im_width,自动计算列数
- lspci详解分析
lspci详解分析 一.PCI简介 PCI是一种外设总线规范.我们先来看一下什么是总线:总线是一种传输信号的路径或信道.典型情况是,总线是连接于一个或多个导体的电气连线,总 线上连接的所有设备可在同一 ...
- Gameia
F - Gameia HDU - 6105 Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes l ...
- MySQL存储过程实践
对employees数据库建立存储过程 创建不含有输入输出变量的存储过程 DELIMITER // -- 设定语句结束分隔符 DROP PROCEDURE IF EXISTS GetEmployees ...
- 周期性任务计划: Crontab
文中部分内容摘自骏马金龙的博客,查看可点击 1. crontab简述 crontab命令用于周期性的执行任务,想要执行这个命令,需要首先启动crond(守护进程)服务才行 crontab是配置管理cr ...