Machine Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5371    Accepted Submission(s): 2658

Problem Description
As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here
we consider a 2-machine scheduling problem.



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. 
 
Input
The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i,
x, y.



The input will be terminated by a line containing a single zero.
 
Output
The output should be one integer per line, which means the minimal times of restarting machine.
 
Sample Input
  1. 5 5 10
  2. 0 1 1
  3. 1 1 2
  4. 2 1 3
  5. 3 1 4
  6. 4 2 1
  7. 5 2 2
  8. 6 2 3
  9. 7 2 4
  10. 8 3 3
  11. 9 4 3
  12. 0
 
Sample Output
  1. 3
  2.  

这题和过山车一模一样。。

就是多了点无用的东西。

。水。。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5.  
  6. using namespace std;
  7.  
  8. const int M = 1000 + 5;
  9. int n, m, k, cas;
  10. int link[M];
  11. bool MAP[M][M];
  12. bool cover[M];
  13. int ans;
  14.  
  15. void init()
  16. {
  17. int x, y;
  18. memset(MAP, false, sizeof(MAP));
  19. for(int i=0; i<k; i++)
  20. {
  21. scanf("%d %d %d", &cas, &x, &y);
  22. if(x&&y)
  23. MAP[x][y]=true;
  24. }
  25. }
  26.  
  27. bool dfs(int x)
  28. {
  29. for(int y=1; y<=m; y++)
  30. {
  31. if(MAP[x][y] && !cover[y])
  32. {
  33. cover[y]=true;
  34. if(!link[y] || dfs(link[y]))
  35. {
  36. link[y]=x;
  37. return true;
  38. }
  39. }
  40. }
  41. return false;
  42. }
  43.  
  44. int main()
  45. {
  46. while(scanf("%d", &n) && n)
  47. {
  48. ans=0;
  49. memset(link, 0, sizeof(link));
  50. scanf("%d %d", &m, &k);
  51. init();
  52. for(int i=1; i<=n; i++)
  53. {
  54. memset(cover, false, sizeof(cover));
  55. if( dfs(i) )
  56. ans++;
  57. }
  58. printf("%d\n", ans);
  59. }
  60.  
  61. return 0;
  62. }

HDU 1150:Machine Schedule(二分匹配,匈牙利算法)的更多相关文章

  1. HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)

    题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...

  2. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

  4. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  5. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  6. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  7. 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule

    二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...

  8. hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. 【01染色法判断二分匹配+匈牙利算法求最大匹配】HDU The Accomodation of Students

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 [DFS染色] #include<iostream> #include<cstdio&g ...

  10. hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版

    //两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...

随机推荐

  1. Ibatis入门基本语法(转) good

    Ibatis入门基本语法 一个项目中在写ibatis中的sql语句时,where user_id in (#user_id_list# ), 运行时总是不行,后来上网查了查,才知道这里不该用#,而应该 ...

  2. JSTL与EL(转)

    基本使用                   <c:forEach items="${deptList}" var="dept">  <div ...

  3. 初试PL/SQL并行编程

    -----------------------------Cryking原创------------------------------ -----------------------转载请注明出处, ...

  4. HDU1284钱币兑换问题( 母函数打表)

    题意:在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. 原题http://acm.hdu.edu.cn/showproblem.php?pid=128 ...

  5. Linux常用命令总结——文件管理

    Linux中的目录 路径:也就是linux中的目录(文件夹)有绝对路径和相对路径 根目录:/ 用户主目录(home directory):位于/home目录下,用户登录时 工作目录(working d ...

  6. 转换DataSet中的多个表为Excel中的多个Sheets

    第一种方法: 1. 在设计页面,有一个button按钮,当用户单击按钮的时候,发生转换 <asp:Button ID="Export" runat="server& ...

  7. tomcat配置没啥难的啊

    总体上就是: 1.下载jdk并安装. 2.下载tomcat 3.分别设置好环境变量. 4.cmd java -version 如果成功,证明java jdk配置OK startup.bat 如果成功 ...

  8. Error D8016 '/ZI' and '/Gy-' command-line options are incompatible

    使用vs运行工程时出现错误: Severity Code Description Project File Line Suppression StateError D8016 '/ZI' and '/ ...

  9. Java map取value最大值和最小值

    /** * 求Map<K,V>中Value(值)的最小值 * * @param map * @return */ public static Object getMinValue(Map& ...

  10. cyq.data开源

    终于等到你:CYQ.Data V5系列 (ORM数据层)最新版本开源了 前言: 不要问我框架为什么从收费授权转到免费开源,人生没有那么多为什么,这些年我开源的东西并不少,虽然这个是最核心的,看淡了就也 ...