hdoj--1150--Machine Schedule(最小点覆盖)
Machine Schedule
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.
each line is a triple: i, x, y.
The input will be terminated by a line containing a single zero.
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
3
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>map[1010];
int used[1010],pipei[1010];
int find(int x)
{
for(int i=0;i<map[x].size();i++)
{
int y=map[x][i];
if(!used[y])
{
used[y]=1;
if(!pipei[y]||find(pipei[y]))
{
pipei[y]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
int a,b,c;
int m,k;
memset(pipei,0,sizeof(pipei));
scanf("%d%d",&m,&k);
for(int i=0;i<=n;i++)
map[i].clear();
while(k--)
{
scanf("%d%d%d",&a,&b,&c);
if(b&&c)
map[b].push_back(c);
}
int sum=0;
for(int i=0;i<n;i++)
{
memset(used,0,sizeof(used));
sum+=find(i);
}
printf("%d\n",sum);
}
return 0;
}
hdoj--1150--Machine Schedule(最小点覆盖)的更多相关文章
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- HDOJ 1150 Machine Schedule
版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss https://blog.csdn.net/u012797220/article/details/3 ...
- 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(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- HDU 1150 Machine Schedule (二分图最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...
- HDU——T 1150 Machine Schedule
http://acm.hdu.edu.cn/showproblem.php?pid=1150 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
随机推荐
- Java数组!!!你知多少?
这是一篇网上搜到的文章,对数组进行了充分的说明.楼主懂了数组的俩种初始化方式:静态初始化和动态初始化方式.(贴过来备用哦) 下面我带大家一起加深一下对Java数组的认识: 1.理解数组 数组也是一种数 ...
- A题时遇到的一些技巧
这篇主要是讲刷题时候遇到的一些技巧,该篇保持持续更新状态.. 1.求数组的长度:int a[]={,,,}; int n = sizeof(a)/sizeof(a[0]) 2.求想上取整,例如7/3 ...
- Android开发之拍照功能实现
参考链接:http://www.linuxidc.com/Linux/2013-11/92892p3.htm 原文链接:http://blog.csdn.net/tangcheng_ok/articl ...
- 错误 RC1015: 无法打开包含文件 'XTToolkitPro.rc'
XtremeToolkitPro作为VC++/MFC平台下目前最流行的GUI界面库之一,安装和使用都很方便.不过,在实际使用中还是碰到许多问题.如果在编译工程时只显示一个错误:RC1015: 无法打开 ...
- eclipse中导入maven项目:org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.proje
org.codehaus.plexus.archiver.jar.Manifest.write(java.io.PrintWriter) 解决方法为:更新eclipse中的maven插件 1.help ...
- js 响应事件
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 启动模拟器的qq
#coding = utf-8from appium import webdriver '''1.手机类型2.版本3.手机的唯一标识 deviceName4.app 包名appPackage5.app ...
- CentOS平滑更新nginx版本
目前使用的nginx版本是1.4.4,平滑升级到nginx1.10.1,具体升级操作流程如下: 1.备份当前使用的nginx程序目录 tar -zcvf ./nginx1.4.4bak.tar.gz ...
- docker安装部署
1. 如何安装 Epel源到 RHEL/CentOS 7/6/5? RHEL/CentOS rpm -ivh http://mirrors.ustc.edu.cn/epel/7/x86_64/Pack ...
- 在vue项目中引用element-ui时 让el-input 获取焦点的方法
在制作项目的时候遇到一个需求,点击一个按钮弹出一个input输入框,并让输入框获得焦点,项目中引用了ElementUI 在网上查找了很多方法,但是在实际使用中发现了一个问题无论是使用$ref获取inp ...