题目链接:http://poj.org/problem?id=1325

Machine Schedule
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14216   Accepted: 6075

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

Source

 
题意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式然后有k个作业,每个作业有三个参数i,a,b,i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成,或者在B机器的b模式下完成,问两个机器总共最少变换多少次可以完成所有作业
 
分析:
最小点覆盖,刚开始是出于0状态下,因此要删掉0与其他点的边,两个集合都要,或者是,都从1开始扫。
然后是:
最小点覆盖 = 最大匹配;
证明:我没退出来,看了网上的证明,很有道理。
首先,最小点集覆盖一定>=最大匹配,因为假设最大匹配为n,那么我们就得到了n条互不相邻的边,光覆盖这些边就要用到n个点。现在我们来思考为什么 最小点击覆盖一定<=最大匹配。任何一种n个点的最小点击覆盖,一定可以转化成一个n的最大匹配。因为最小点集覆盖中的每个点都能找到至少一条只有 一个端点在点集中的边(如果找不到则说明该点所有的边的另外一个端点都被覆盖,所以该点则没必要被覆盖,和它在最小点集覆盖中相矛盾),只要每个端点都选 择一个这样的边,就必然能转化为一个匹配数与点集覆盖的点数相等的匹配方案。所以最大匹配至少为最小点集覆盖数,即最小点击覆盖一定<=最大匹配。 综上,二者相等。
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int n,m,k;
  5. bool maps[][];
  6. int match[];
  7. bool use[];
  8.  
  9. bool DFS(int u)
  10. {
  11. for(int i=;i<m;i++)
  12. {
  13. if(!use[i]&&maps[u][i])
  14. {
  15. use[i] = true;
  16. if(match[i]==-||DFS(match[i]))
  17. {
  18. match[i] = u;
  19. return true;
  20. }
  21. }
  22. }
  23. return false;
  24. }
  25.  
  26. int main()
  27. {
  28. while(scanf("%d",&n))
  29. {
  30. if(n==) break;
  31. scanf("%d%d",&m,&k);
  32. memset(maps,false,sizeof(maps));
  33. memset(match,-,sizeof(match));
  34.  
  35. for(int i=;i<k;i++)
  36. {
  37. int t,a,b;
  38. scanf("%d%d%d",&t,&a,&b);
  39. maps[a][b] = true;
  40. }
  41. /*for(int i=0;i<m;i++)
  42. {
  43. if(maps[0][i])
  44. maps[0][i] = false;
  45. }
  46. for(int i=0;i<n;i++)
  47. {
  48. if(maps[i][0])
  49. maps[i][0] = false;
  50. }*/
  51. int num = ;
  52. for(int i=;i<n;i++)
  53. {
  54. memset(use,false,sizeof(use));
  55. if(DFS(i))
  56. num++;
  57. }
  58. printf("%d\n",num);
  59. }
  60. return ;
  61. }
 

Poj(1325),最小点覆盖的更多相关文章

  1. POJ 2226 最小点覆盖(经典建图)

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8881   Accepted: 3300 Desc ...

  2. POJ 2446 最小点覆盖

    Chessboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14787   Accepted: 4607 Descr ...

  3. poj 3041 最小点覆盖=最大匹配

    #include<stdio.h> #include<string.h> #define  N  510 int map[N][N],n,mark[N],link[N]; in ...

  4. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  5. POJ 1325 Machine Schedule(最小点覆盖)

    http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...

  6. POJ - 1325 Machine Schedule 二分图 最小点覆盖

    题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...

  7. POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ...

  8. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  9. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

随机推荐

  1. CSS3 auto revolution practitioner!

    1.html <!DOCTYPE html> <html> <head> <title></title> <meta charset= ...

  2. 大数据Spark超经典视频链接全集

    论坛贴吧等信息发布参考模板 Scala.Spark史上最全面.最详细.最彻底的一整套视频全集(特别是机器学习.Spark Core解密.Spark性能优化.Spark面试宝典.Spark项目案例等). ...

  3. Ruby界面开发--wxRuby库TextCtrl相关问题

    界面库官方教程:(1) 总的各种库函数讲解http://wxruby.rubyforge.org/doc/index.html (2)TextCtrl讲解 http://wxruby.rubyforg ...

  4. 在 msbuild 生成时,每次都生成很多css,js,img 文件,如果不想每次编译都有这些需要这样配置

    在 msbuild 不想生成一大堆文件,可以在 Web 项目的csproj 文件里,注释掉这一串. <!--<Import Project="$(VSToolsPath)\Web ...

  5. AS-demo09

    ,mainifast: <uses-permission android:name="android.permission.SET_WALLPAPER"/> , < ...

  6. OpenCV cv::Mat类

    using namespace cv; 1.Mat的声明: Mat m=Mat(rows, cols, type); Mat m=Mat(Size(width,height), type); type ...

  7. mybatis 复习笔记03

    参考:http://www.mybatis.org/mybatis-3/zh/configuration.html 入门 1. 从 XML 中构建 SqlSessionFactory 每个基于 MyB ...

  8. Sensor信号输出YUV、RGB、RAW DATA、JPEG【转】

    本文转载自:http://blog.csdn.net/southcamel/article/details/8305873 简单来说,YUV: luma (Y) + chroma (UV) 格式, 一 ...

  9. chrome调试找不到 XXXX.min.map 原因及解决办法

    什么是source map文件. source map文件是js文件压缩后,文件的变量名替换对应.变量所在位置等元信息数据文件,一般这种文件和min.js主文件放在同一个目录下. 比如压缩后原变量是m ...

  10. zabbix监控phpfpm

    php-fpm status详解 pool – fpm池子名称,大多数为wwwprocess manager – 进程管理方式,值:static, dynamic or ondemand. dynam ...