杭电 hdu 1150 Machine Schedule (二分匹配)

杭电  hdu 1150  Machine Schedule  (二分匹配)



Machine Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6694    Accepted Submission(s): 3353


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
  
  
5 5 10 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
 

Sample Output
  
  
3
 

Source
 

Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:   1281  1528  1054  1498  1533 
 







题意:有很多的工作,而现在有两个机器人,对于每个工作,会给出第一个机器人要用那个模式可以做,第二个机器人要用哪个模式去做
但是换机器人,或者同个机器人换模式,都是要浪费一次时间,希望怎么的选择可以使浪费的时间最少
首先给出n,m,T
n表示第一个机器人有多少模式
m表示第二个机器人有多少模式
T表示有多少工作
接下来是T行,分别a,b,c三个数字
a表示第几个工作
b表示可以用第一个机器人的b模式解决
c表示可以用第二个机器人的c模式解决
等输出只有一个0的时候表示结束




题解:其实就是不用去管它第一个工作之类的,只要看两个机器人的模式就可以了,在一个机器人的一种模式很多的时候,就选择这个模式,
舍弃多重复杂的模式,这样就能抱住转换最少。
这就是一种二分匹配,通过选择多种相同的模式当作1,只能匹配一次,从而找最大匹配数就是答案。



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>


using namespace std;


int n, m;
bool map[105][105];                //用来记录两个机器人直接模式的关系的矩阵,0表示没有关系,1表示连接
bool vis[1005];
int pri[1005];               //用来记录下标下的数字,最终和谁连接


bool find (int x)
{
    int i;


    for (i = 1; i <= m; i++)
    {
        if (map[x][i] && !vis[i])               //选择有连接关系的,同时第一次或者是之后用来记录i这个点被暂时标记
        {
            vis[i] = true;
            if (pri[i] == -1 || find(pri[i]))             //先看是否点被选择走了,如果选择走了,就看看选走的那个人还有其它可选择的点
            {
                pri[i] = x;
                return true;
            }
        }
    }
    return false;
}


int main ()
{
    int k, a, b, c, i;


    while (scanf ("%d", &n) != EOF)
    {
        if (n == 0)
            return 0;
        scanf ("%d%d", &m, &k);
        memset (map, false, sizeof (map));
        memset (pri, -1, sizeof (pri));
        for (i = 0; i < k; i++)
        {
            scanf ("%d%d%d", &a, &b, &c);
            map[b][c] = true;                  //只记录一二两个机器人的模式就可以了
        }
        int ans = 0;
        for (i = 1; i <= n; i++)
        {
            memset (vis, false, sizeof (vis));
            if (find (i))
                ans++;
        }
        printf ("%d\n", ans);
    }


    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
城市应急指挥系统是智慧城市建设的重要组成部分,旨在提高城市对突发事件的预防和处置能力。系统背景源于自然灾害和事故灾难频发,如汶川地震和日本大地震等,这些事件造成了巨大的人员伤亡和财产损失。随着城市化进程的加快,应急信息化建设面临信息资源分散、管理标准不统一等问题,需要通过统筹管理和技术创新来解决。 系统的设计思路是通过先进的技术手段,如物联网、射频识别、卫星定位等,构建一个具有强大信息感知和通信能力的网络和平台。这将促进不同部门和层次之间的信息共享、交流和整合,提高城市资源的利用效率,满足城市对各种信息的获取和使用需求。在“十二五”期间,应急信息化工作将依托这些技术,实现动态监控、风险管理、预警以及统一指挥调度。 应急指挥系统的建设目标是实现快速有效的应对各种突发事件,保障人民生命财产安全,减少社会危害和经济损失。系统将包括预测预警、模拟演练、辅助决策、态势分析等功能,以及应急值守、预案管理、GIS应用等基本应用。此外,还包括支撑平台的建设,如接警中心、视频会议、统一通信等基础设施。 系统的实施将涉及到应急网络建设、应急指挥、视频监控、卫星通信等多个方面。通过高度集成的系统,建立统一的信息接收和处理平台,实现多渠道接入和融合指挥调度。此外,还包括应急指挥中心基础平台建设、固定和移动应急指挥通信系统建设,以及应急队伍建设,确保能够迅速响应并有效处置各类突发事件。 项目的意义在于,它不仅是提升灾害监测预报水平和预警能力的重要科技支撑,也是实现预防和减轻重大灾害和事故损失的关键。通过实施城市应急指挥系统,可以加强社会管理和公共服务,构建和谐社会,为打造平安城市提供坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值