题目大意:给定 N 个任务和两台机器,每个任务可以在任意一台机器上执行,每台机器有 N 个启动状态,不同任务需要机器在不同的状态下执行,求执行所有任务需要多少个不同的状态。

题解:由于一个任务一定要被两台机器中的一台执行,可以将任务看作边,连接两台机器的对应启动状态。所要求的是这个二分图的最大独立集,因此,只需求出其最大匹匹数即可。

代码如下

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
//const int maxn=
const double eps=1e-6;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll sqr(ll x){return x*x;}
inline ll read(){
ll x=0,f=1;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
return f*x;
}
/*--------------------------------------------------------*/ vector<int> G[101];
int match[101];bool vis[101];
int n,m,q,ans; void read_and_parse(){
m=read(),q=read();
for(int i=1;i<=q;i++){
int d=read(),x=read(),y=read();
G[x].pb(y);
}
} bool dfs(int u){
for(auto v:G[u])if(!vis[v]){
vis[v]=1;
if(!match[v]||dfs(match[v])){
match[v]=u;return 1;
}
}
return 0;
} void solve(){
for(int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
if(dfs(i))++ans;
}
printf("%d\n",ans);
} void init(){
ans=0;
for(int i=1;i<=100;i++)G[i].clear();
memset(match,0,sizeof(match));
} int main(){
while(n=read()){
init();
read_and_parse();
solve();
}
return 0;
}

【UVA1194】Machine Schedule的更多相关文章

  1. 【Poj1325】Machine Schedule机器调度

    目录 List Description Input Output Sample Input Sample Output HINT Solution Code Position: http://poj. ...

  2. 【HDU 1150】Machine Schedule(二分图匹配)

    机器的不同模式为点,对于每个job,建两条边 A机器需要的模式<->B机器需要的模式. 问题转化为最小点覆盖,然后用二分图的最小点覆盖==最大匹配,用匈牙利算法解. #include &l ...

  3. 【leetcode】Course Schedule(middle)☆

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  4. 【最大流】【HDU3572】Task Schedule

    题意: 有N个事件,M台机器.事件有开始时间,持续时间,要在结束时间之前完成,问是否能完成所有事件? 非自己思考出来的 建图:把每个任务和每一天都看做一个点,添加源点和汇点.源点与每个任务之间连一条边 ...

  5. 【hdu3842】 Machine Works

    http://acm.hdu.edu.cn/showproblem.php?pid=3842 (题目链接) 题意 一个公司使用一个厂房$D$天,希望获利最大.有$n$台机器,每一台可以在第$D_i$天 ...

  6. 【332】Machine Learning

    Reference: 决策树方法-对买电脑进行分类预测 Reference: 最邻近规则分类(K-Nearest Neighbor)KNN算法应用 Reference: python 内建函数 str ...

  7. 【贪心】hdu6180 Schedule

    题意:给你n个任务的开始时间和结束时间,一个机器同时最多执行一个任务,问你最少要几个机器.保证机器最少的前提下,问你每个机器的开动时间(最后一次关闭-第一次开启)之和最少是多少. 把这些线段画在数轴上 ...

  8. 【hdu4045】Machine scheduling(dp+第二类斯特林数)

    传送门 题意: 从\(n\)个人中选\(r\)个出来,但每两个人的标号不能少于\(k\). 再将\(r\)个人分为不超过\(m\)个集合. 问有多少种方案. 思路: 直接\(dp\)预处理出从\(n\ ...

  9. 【leecode】 Course Schedule

    class Solution { public: static bool canFinish(int numCourses, vector<pair<int, int>>&am ...

随机推荐

  1. Spring是如何校验XML的

    首先来看下xml的一些概念: xml的schema里有namespace,可以给它起个别名.比如常见的spring的namespace: xmlns:mvc="http://www.spri ...

  2. php7函数,声明,返回值等新特性介绍

    使用 ... 运算符定义变长参数函数 (PHP 5 >= 5.6.0, PHP 7) 现在可以不依赖 func_get_args(), 使用 ... 运算符 来实现 变长参数函数. functi ...

  3. python中的 list (列表)append()方法 与extend()方法的用法 和 区别

    参考: https://www.cnblogs.com/xuchunlin/p/5479119.html

  4. git放弃修改,强制覆盖本地代码

    $ git fetch --all $ git reset --hard origin/master $ git pull

  5. Redis 禁用FLUSHALL FLUSHDB KEYS 命令

      (error) ERR unknown command 'keys'问题解决(error) ERR unknown command 'FLUSHDB' 问题解决 背景 FLUSHALL FLUSH ...

  6. Spring Boot 构建电商基础秒杀项目 (八) 商品创建

    SpringBoot构建电商基础秒杀项目 学习笔记 新建数据表 create table if not exists item ( id int not null auto_increment, ti ...

  7. 法语Linux NuTyX 11 RC2 发布

    读 NuTyX是一个法语Linux发行版(具有多语言支持),由Linux From Scratch和Beyond Linux From Scratch构建,带有一个名为“cards”的自定义包管理器. ...

  8. DRF 视图和路由

    Django Rest Feamework 视图和路由 DRF的视图 APIView 我们django中写CBV的时候继承的是View,rest_framework继承的是APIView,那么他们两个 ...

  9. 学习Android过程中遇到的未解决问题(个人笔记,细节补充,随时更新)

    201811/13 使用HttpURLConnection对象调用方法又出现IO异常,我又百度个博客搜寻答案,未果.下午试试真机,完美.自己建了服务器tomcat,编写android访问自己tomca ...

  10. 面向对象—的__new__()方法详解

    [Python] Python 之 __new__() 方法与实例化   __new__() 是在新式类中新出现的方法,它作用在构造方法建造实例之前,可以这么理解,在 Python 中存在于类里面的构 ...