hdoj 1054 Strategic Game【匈牙利算法+最小顶点覆盖】
Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5783 Accepted Submission(s): 2677
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:
#include<stdio.h>
#include<string.h>
#define MAX 1550
int map[MAX][MAX],vis[MAX],point[MAX];
int t;
int find(int x)
{
int i;
for(i=0;i<t;i++)
{
if(map[x][i]&&!vis[i])
{
vis[i]=1;
if(point[i]==0||find(point[i]))
{
point[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,s,n,m;
int a;
while(scanf("%d",&t)!=EOF)
{
memset(map,0,sizeof(map));
memset(point,0,sizeof(point));
for(i=0;i<t;i++)
{
scanf("%d:(%d)",&n,&m);
for(j=0;j<m;j++)
{
scanf("%d",&a);
map[n][a]=map[a][n]=1;//此处要将map[n][a]和map[a][n]同时标记
}
}
s=0;
for(i=0;i<t;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
s++;
}
printf("%d\n",s/2);//因为上边双向同时标记所以s算重复了 所以要除以2
}
return 0;
}
hdoj 1054 Strategic Game【匈牙利算法+最小顶点覆盖】的更多相关文章
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU1054 Strategic Game——匈牙利算法
Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he canno ...
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- poj3041 Asteroids 匈牙利算法 最小点集覆盖问题=二分图最大匹配
/** 题目:poj3041 Asteroids 链接:http://poj.org/problem?id=3041 题意:给定n*n的矩阵,'X'表示障碍物,'.'表示空格;你有一把枪,每一发子弹可 ...
- POJ 3041 Asteroids(二分图 && 匈牙利算法 && 最小点覆盖)
嗯... 题目链接:http://poj.org/problem?id=3041 这道题的思想比较奇特: 把x坐标.y坐标分别看成是二分图两边的点,如果(x,y)上有行星,则将(x,y)之间连一条边, ...
- hdoj 1083 Courses【匈牙利算法】
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- Asteroids POJ - 3041 匈牙利算法+最小点覆盖König定理
题意: 给出一个N*N的地图N 地图里面有K个障碍 你每次可以选择一条直线 消除这条直线上的所有障碍 (直线只能和列和行平行) 问最少要消除几次 题解: 如果(x,y)上有一个障碍 则把 ...
- Strategic Game HDU - 1054(最小顶点覆盖)
最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联: ...以为自己很聪明..用边连边...最后还是点连点 哎.... hc 写的 匈牙利足够///// #include <iostr ...
- HDU ACM 1054 Strategic Game 二分图最小顶点覆盖?树形DP
分析:这里使用树形DP做. 1.最小顶点覆盖做法:最小顶点覆盖 == 最大匹配(双向图)/2. 2.树形DP: dp[i][0]表示i为根节点,而且该节点不放,所需的最少的点数. dp[i][1]表示 ...
随机推荐
- Invoke()方法的使用
在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法是错误的做法,Invoke 和 BeginInvoke 就是为了解决这个问题而出现的,使你在多线程中安全的更新界 ...
- PHP设计模式之工厂/单例/注册者模式
工厂模式 简单工厂模式 [静态工厂方法模式](Static Factory Method)是类的创建模式 工厂模式的几种形态: 1.简单工厂模式(Simple Factory)又叫做 静态工厂方法模式 ...
- RegexKitLite 使用详解
1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中. 2.工程中添加libicucore.dylib frameworks. 友情提醒:一般 ...
- ubuntu13.10 登陆后黑屏,没有菜单栏,可以启动termina,怎么解决?
最近在学习openGL,自己的电脑是intel集显加nvidia GT630M,本来想应该可以支持到opengl4以上的,可是发现nvidia的显卡由于驱动问题,好像一直没有用到,所以只支持了open ...
- bzoj 3597: [Scoi2014]方伯伯运椰子 0/1分数规划
3597: [Scoi2014]方伯伯运椰子 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 144 Solved: 78[Submit][Status ...
- jquery mobile backbone
http://www.appliness.com/getting-started-with-html-mobile-application-development-using-jquery-mobil ...
- Z-Stack 软件架构分析
转自Z-Stack 软件架构分析 Z-Stack的main函数在Zmain.c中,总体上来说,它一共做了两件工作,一个是系统初始化,即有启动代码来初始化硬件系统和软件架构需要的各个模块,另一个作用就是 ...
- Mongodb数据更新命令
一.Mongodb数据更新命令 Mongodb更新有两个命令:update.save. 1.1update命令 update命令格式: db.collection.update(criteria,ob ...
- http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
- CSS3实现的player播放按钮
完成的效果如下 查看效果并下载 Step 1:先了解border的原理: Step 2:HTML代码结构 <section class="playContainer"> ...