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) ...
随机推荐
- -bash: mysql: command not found 之 MAC
第一次尝试: ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 提示:Operation not permitted 再次,加sudo附上管理员权限,依旧 ...
- app支付宝授权登录获取用户信息
由后台进行地址的拼接(前台进行授权) // 生成授权的参数 String sign = ""; Long userId1 = SecurityUser.getUserId(); S ...
- js生成随机的uuid
function generateUUID() { var d = new Date().getTime(); if(window.performance && typeof wind ...
- PHP 中空字符串介绍0、null、empty和false之间的关系
0是数字,是empty,是false,不是null,值相当于空字符串,但类型不是字符串,去空格或强制转换为字符串型时不等于空字符串 ""的值相当于0,是empty,是空字符串,是f ...
- MFC限制窗口大小
MFC限制窗口大小 使用:WM_GETMINMAXINFO message void OnGetMinMaxInfo(MINMAXINFO* lpMMI) { lpMMI->ptMinTrack ...
- css内容补充之其它
1.overflow 当图片大小,超出div的大小时,可以指定overflow值为auto(带滚动条).hidden(隐藏,只显示一块): hover 当鼠标移动到当前标签上时,以下css属性才生效:
- pycharm 用远程环境时报错bash: line 0: cd: /home/tmp: No such file or directory
delete redundant path
- 洛谷 P3146 248 题解
https://www.luogu.org/problemnew/show/P3146 区间dp,这次设计的状态和一般的有一定的差异. 这次我们定义$dp[i][j]$表示$[i,j]$的可以合并出来 ...
- Oracle数据库日常SQL的使用
DDL 语句(数据定义语言Create.Alter. Drop.Truncate) 1.建表:create table 表名(): 2.复制表结构及其数据:create table 新表名 as se ...
- thinkphp5实现文件上传
原理:通过form表单的enctype = "multipart / form-data"属性将文件临时放在htdocs文件夹的tmp目录下,再通过后台的程序将文件保存在自己设定的 ...