hdu1150&&POJ1325 Machine Schedule---最小点覆盖
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1150
题目大意:
给你两台机器A和B,A机器有n种模式,B机器有m种模式,初始时都是0,现在给你k个任务,每个任务可以由机器A的x模式完成或者机器B的y模式完成,而每次改变机器的模式都要重启一次,问你最少的重启次数使得完成所有任务!
解题思路:
首先初始化为0,所以有模式0完成的任务可以不考虑,然后我们可以考虑建立二分图,机器A和机器B的模式互相连接,某个任务由A的x和B的y完成那么x与y相连,所以我们转换下题目的模型就是在这个二分图中找出最少的点使得所有的边都至少有一个端点被选中,而这就是最小点覆盖的模型,而最小点覆盖=最大匹配
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = + ;
const int INF = 1e9;
bool Map[maxn][maxn];
int cx[maxn], cy[maxn];
int cntx, cnty;
bool vis[maxn];
bool dfs(int u)
{
for(int v = ; v <= cnty; v++)
{
if(Map[u][v] && !vis[v])
{
vis[v] = ;
if(cy[v] == - || dfs(cy[v]))
{
cx[u] = v;
cy[v] = u;
return ;
}
}
}
return ;
}
int maxmatch()
{
int ans = ;
memset(cx, -, sizeof(cx));
memset(cy, -, sizeof(cy));
for(int i = ; i <= cntx; i++)
{
if(cx[i] == -)
{
memset(vis, , sizeof(vis));
ans += dfs(i);
}
}
return ans;
}
int main()
{
int n, i, u, v;
while(cin >> cntx && cntx)
{
cin >> cnty >> n;
memset(Map, , sizeof(Map));
while(n--)
{
cin >> i >> u >> v;
Map[u][v] = ;
}
cout<<maxmatch()<<endl;
}
return ;
}
hdu1150&&POJ1325 Machine Schedule---最小点覆盖的更多相关文章
- poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- POJ1325 Machine Schedule(二分图最小点覆盖集)
最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- POJ1325 Machine Schedule
Description As we all know, machine scheduling is a very classical problem in computer science and h ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- POJ-1325 Machine Schedule,和3041有着异曲同工之妙,好题!
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Description As we all know, machine ...
随机推荐
- PHP连接 redis
<?php //连接本地的 Redis 服务 $redis = new Redis(); //连接redis 地址 端口 连接超时时间 连接成功返回true 失败返回false $redis-& ...
- Docker 启动配置和远程访问
1. 添加Docker 启动时的配置: vi /etc/default/docker 添加: DOCKER_OPTS=" --label name=dockerServer1 -H ...
- C#之数据类型转换
前言 在C#中学习中,像在VB学习的时候一样,我们会接触到很多种数据类型,但是VB中在用数据类型的时候,我们会考虑这个数据要求多大的内存,或者说有时候为了满足很少的大内存事件,而狠心分配给它较大 ...
- SSM框架的集成
一 : SpringMVC 接收参数 基本数据类型+String JavaBean 一对一 一对多 Map List 注解 @RequestMapping("/user/add") ...
- Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)
B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- thinphp5会员注册邮箱验证
1.首先完成邮箱发送http://www.cnblogs.com/jcydd/p/7299750.html 2.在完成会员新增后执行后置函数,在模型类当中 //注册后置函数 protected sta ...
- CCF201809(Java)
第一题: 问题描述 在一条街上有n个卖菜的商店,按1至n的顺序排成一排,这些商店都卖一种蔬菜. 第一天,每个商店都自己定了一个价格.店主们希望自己的菜价和其他商店的一致,第二天,每一家商店都会根据他自 ...
- Migration-添加表(加外键)
public partial class _222 : DbMigration { public override void Up() { //DropForeignKey("dbo.Ass ...
- Excel去除空行
本文转载至:https://baijiahao.baidu.com/s?id=1590204478648348952&wfr=spider&for=pc,需要详细信息可链接查看 方法一 ...
- Microsoft JET Database Engine (0x80004005)未指定的错误解决
Microsoft JET Database Engine (0x80004005)未指定的错误,这个错误只有在使用Access数据库时才能出现 出现以上问题,可以使用以下步骤进行解决问题: 1.系统 ...