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模式完成,同时变换一次模式需要重新启动一次 ...
随机推荐
- 求和函数 sum详解
sum()的参数是一个list: >>> sum([1,2,3]) 6 >>> sum(range(1,3)) 3 还有一个比较有意思的用法 a = range(1 ...
- 欢迎使用skymvc框架,简单易用的php框架
skymvc是一款轻量.简单易用的php mvc框架,经过多个项目实践改良. 特点: 1.mvc架构 2.m.v.c之间可以互相调用 3.简单的路由控制 R("/index.php" ...
- yii2源码学习笔记(十一)
Controller控制器类,是所有控制器的基类,用于调用模型和布局. <?php /** * @link http://www.yiiframework.com/ * @copyright C ...
- CentOS使用sudo提示用户不在sudoers文件中的解决方法
1切换到root用户[linux@localhost ~]$ su root密码:[root@localhost ~]# 2查看/etc/sudoers文件权限,如果只读权限,修改为可写权限 [roo ...
- “\n”与“\r”的区别
ASCII中“\n”代表着换行,“\r”代表着将光标移动到当前显示行的最左边.
- 对SVM的个人理解
对SVM的个人理解 之前以为SVM很强大很神秘,自己了解了之后发现原理并不难,不过,“大师的功力在于将idea使用数学定义它,使用物理描述它”,这一点在看SVM的数学部分的时候已经深刻的体会到了,最小 ...
- 重燃你的PHP安全分析之火
关于脚本安全这个话题好像永远没完没了,如果你经常到国外的各种各样的bugtraq上,你会发现有一半以上都和脚本相关,诸如SQL injection,XSS,Path Disclosure,Remote ...
- Stanford CoreNLP--常量定义
在运行Stanford CoreNLP过程中会用到tokenize,pos等参数,这些以常量形式定义在edu.stanford.nlp.pipeline.Annotator中,具体如下: /** * ...
- [ecmall]Ecmall 后台添加模板编辑区
例如,想把品牌/index.php?app=brand页面做成可编辑的. 首先,找到后台admin\includes\menu.inc.php第61行 'template' => array( ...
- ANDROID_MARS学习笔记_S03_005_Geocoder、AsyncTask
一.代码1.xml(1)AndroidManifest.xml <uses-permission android:name="android.permission.ACCESS_FIN ...