POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, …, mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, … , mode_m-1. At the beginning they are both work at mode_0.
For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.
Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.
The input will be terminated by a line containing a single zero.
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std ;
const int MAXN = 105 ;
short g[MAXN][MAXN] ;
bool vis[MAXN] ;
short cx[MAXN] , cy[MAXN] ;
int n , m , k ;
void init()
{
memset(g , 0 , sizeof(g)) ;
memset(cx , -1 , sizeof(cx)) ;
memset(cy , -1 , sizeof(cy)) ;
int i ;
for(i = 0 ; i < k ; i ++)
{
int a , b , c ;
scanf("%d%d%d" , &a , &b ,&c) ;
if(b != 0 && c != 0)
{
g[b][c] = 1 ;
}
}
}
int path(int v)
{
int i ;
for(i = 0 ; i < m ; i ++)
{
if(g[v][i] && !vis[i])
{
vis[i] = 1 ;
if(cy[i] == -1 || path(cy[i]))
{
cy[i] = v ;
cx[v] = i ;
return 1 ;
}
}
}
return 0 ;
}
void solve()
{
int i ;
int ans = 0 ;
for(i = 0 ; i < n ; i ++)
{
if(cx[i] == -1)
{
memset(vis , 0 , sizeof(vis)) ;
if(path(i))
ans ++ ;
}
}
printf("%d\n" , ans) ;
}
int main()
{
while (scanf("%d" , &n) != EOF)
{
if(n == 0)
break ;
scanf("%d%d" , &m , &k) ;
init() ;
solve() ;
}
return 0 ;
}
POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang的更多相关文章
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...
- 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 hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
- 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: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- hdu 1150 Machine Schedule 最小覆盖点集
题意:x,y两台机器各在一边,分别有模式x0 x1 x2 ... xn, y0 y1 y2 ... ym, 现在对给定K个任务,每个任务可以用xi模式或者yj模式完成,同时变换一次模式需要重新启动一次 ...
随机推荐
- 使用WMI监控进程启动与结束
需要添加引用System.Management 代码: static void Main(string[] args) { //创建WQL事件查询,监视进程开启 var qCreate = new W ...
- C#中指针使用总结
C#为了类型安全,默认并不支持指针.但是也并不是说C#不支持指针,我们可以使用unsafe关键词,开启不安全代码(unsafe code)开发模式.在不安全模式下,我们可以直接操作内存,这样就可以使用 ...
- [转]iOS之浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法
参考:http://www.mamicode.com/info-detail-469709.html 一.最普通的视图控制器UIViewContoller 一个普通的视图控制器一般只有模态跳转的功能( ...
- zzuli oj 1145 有问题的里程表 2
Description 某辆汽车有一个里程表,该里程表可以显示一个整数,为该车走过的公里数.然而这个里程表有个毛病:它总是从3变到5,而跳过数字4,里程表所有位(个位. 十位.百位等)上的数字都是如此 ...
- SQL函数:小写金额转换成大写
/********************************************************作者:版本:1.0创建时间:20020227修改时间:功能:小写金额转换成大写参数:n ...
- MYSQL数据库备份与恢复【转】
mysqldump -h主机名 -P端口 -u用户名 -p密码 (–database) 数据库名 > 文件名.sql 在window上需要通过CMD进入mysql安装目录下的bin目录下执行 ...
- leetcode第三题Longest Substring Without Repeating Characters java
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...
- 好吧,如果一定要RESTFUL的DJANGO
看看人家写的VIEWSET, 然后用REQUESTS测试一下. from rest_framework import viewsets from rest_framework.decorators i ...
- Performance Test of List<T>, LinkedList<T>, Queue<T>, ConcurrentQueue<T>
//Test Group 1 { var watch = Stopwatch.StartNew(); var list = new List<int>(); ; j < ; j++) ...
- [转贴]一个将表格变成 INSERT 的SQL 语句的存储过程(sql server)
来源自http://vyaskn.tripod.com/code.htm#inserts SET NOCOUNT ON GO PRINT 'Using Master database' USE mas ...