XMU 1040 Schedule 【拓扑排序】
1040: Schedule
Time Limit: 500 MS Memory Limit: 64 MB
Submit: 12 Solved: 2
[Submit][Status][Web Board]Description
Resently, loneknight is doing research on job shop schedule problem(JSP for short). Let us take a look at JSP, there are n jobs and m machines, and every job must be processed in every machines, with a process time t[i,j] for job i being processed in machines j. One restrain is that the order for each job processed in machines is fixed, which means that for every job i, there is a process oder (a[i,1], a[i,2], ..., a[i,m]), job i must processed in machine a[i,1] first then a[i,2], ..., a[i,m]. Another restrain is every machine can process amost one job at any time, and every job can be process in amost one machine at any time. The problem is to find a schedule fit this restrains, that make the end time for all jobs, namely the makespan is minimum. Because of the fact that JSP is a NP-Complete problem, loneknight try using simulated anealing and gene algorithm to construct a heuristics algorithm for it. In developing such algorithm for JSP, he confront with a problem that if a schedule is already given, what is the makespan of this schedule, now this your task to solve this problem.
Input
There are mutiple test cases in the input. The beginning of each case is n, the number of jobs, m, the number of machines. (0 < n,m <= 300) Each follow three components. First is a nxm matrix, the value in the ith row and jth column is t[i,j]. (0 <= t[i,j] < 100) Second is a nxm matrix, the jobs process order, the value in the ith row and jth column is a[i,j]. Third is a mxn matrix the machines process order, the value in the ith row and jth column is b[i,j], (b[i,1], b[i,2], ..., b[i,n]) is the jobs process order in machine i, which means machine i process b[i,1] first, then b[i,2], ..., b[i,n]. (jobs and machines are indexed from 1) The input end with EOF
Output
For each test case, you should output a single integer, which is the makespan for that schedule in a single line.
Sample Input
3 3
83 86 77
15 93 35
86 92 493 1 2
3 1 2
1 3 21 2 3
1 3 2
1 2 3Sample Output
495
HINT
Source
题目链接:
http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1040
题目大意:
有N个任务,M台机器,每个任务都必须在M台机器上运行一次才行。
任务i在机器j上的运行时间为T[i][j]
任务i必须满足先在机器A[i][1]上运行完才能在A[i][2]上,A[i][3]...A[i][m]上(按A[i]的顺序运行)
机器j必须满足先运行任务B[j][1]才能再运行B[j][2],...,B[j][n](按B[j]顺序运行)
问所有任务完成的时间。
题目思路:
【拓扑排序】
首先可以知道,如果一个任务在某一个机器上做需要之前的步骤都已经完成,每一个机器做当前任务也需要之前的任务均完成
所以按照这个建图,按照第i个任务第j个机器设为节点A[i][j]。由于每个任务都有机器的先后顺序,每个机器也有任务的先后顺序
所以A[i][j]往它的下一个任务,下一个机器连一条边。
(一开始用SPFA写T了。。)
之后拓扑排序,每次更新最长路径的值。最后的答案即为解。
d[xx][yy]=max{ d[x][y]+t[xx][yy] }
/**************************************************** Author : Coolxxx
Copyright 2017 by Coolxxx. All rights reserved.
BLOG : http://blog.csdn.net/u010568270 ****************************************************/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
const double EPS=1e-;
const int J=;
const int MOD=;
const int MAX=0x7f7f7f7f;
const double PI=3.14159265358979323;
const int N=;
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int t[N][N],a[N][N],b[N][N],d[N][N],in[N][N];
int nex[N][N][][];
void tuopu()
{
int i,j,x,y,xx,yy;
mem(d,);
queue<int>qx,qy;
for(i=;i<=n;i++)
{
if(!in[i][a[i][]])
{
d[i][a[i][]]=t[i][a[i][]];
qx.push(i);
qy.push(a[i][]);
}
}
while(!qx.empty())
{
x=qx.front();qx.pop();
y=qy.front();qy.pop();
for(i=;i<;i++)
{
xx=nex[x][y][i][];
yy=nex[x][y][i][];
if(!x || !y)continue;
d[xx][yy]=max(d[xx][yy],d[x][y]+t[xx][yy]);
if(!--in[xx][yy])
{
qx.push(xx);
qy.push(yy);
}
}
ans=max(ans,d[x][y]);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k,l;
int x,y,z;
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
ans=;
mem(nex,);mem(in,);
scanf("%d",&m);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&t[i][j]);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&a[i][j]);
for(i=;i<=m;i++)
for(j=;j<=n;j++)
scanf("%d",&b[i][j]);
for(i=;i<=n;i++)
{
for(j=;j<m;j++)
{
nex[i][a[i][j]][][]=i,
nex[i][a[i][j]][][]=a[i][j+];
in[i][a[i][j+]]++;
}
}
for(i=;i<=m;i++)
{
for(j=;j<n;j++)
{
nex[b[i][j]][i][][]=b[i][j+],
nex[b[i][j]][i][][]=i;
in[b[i][j+]][i]++;
}
}
tuopu();
printf("%d\n",ans);
}
return ;
}
/*
// //
*/
XMU 1040 Schedule 【拓扑排序】的更多相关文章
- LeetCode 210. Course Schedule II(拓扑排序-求有向图中是否存在环)
和LeetCode 207. Course Schedule(拓扑排序-求有向图中是否存在环)类似. 注意到.在for (auto p: prerequistites)中特判了输入中可能出现的平行边或 ...
- LeetCode 207. Course Schedule(拓扑排序)
题目 There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have p ...
- 2-sat 输出任意一组可行解&拓扑排序+缩点 poj3683
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8170 Accept ...
- Poj 3683-Priest John's Busiest Day 2-sat,拓扑排序
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8872 Accept ...
- LeetCode编程训练 - 拓扑排序(Topological Sort)
拓扑排序基础 拓扑排序用于解决有向无环图(DAG,Directed Acyclic Graph)按依赖关系排线性序列问题,直白地说解决这样的问题:有一组数据,其中一些数据依赖其他,问能否按依赖关系排序 ...
- 拓扑排序 Topological Sort
2018-05-02 16:26:07 在计算机科学领域,有向图的拓扑排序或拓扑排序是其顶点的线性排序,使得对于从顶点u到顶点v的每个有向边uv,u在排序中都在v前.例如,图形的顶点可以表示要执行的任 ...
- hdu 4857(好题,反向拓扑排序)
逃生 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- Gym 100792 King's Rout 拓扑排序
K. King's Rout time limit per test 4.0 s memory limit per test 512 MB input standard input output st ...
- poj 3683(2-sat+拓扑排序)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11127 Accep ...
随机推荐
- 51node 1134 最长递增子序列 (数据结构)
题意: 最长递增子序列 思路: 普通的$O(n^2)$的会超时.. 然后在网上找到了另一种不是dp的写法,膜拜一下,自己写了一下解释 来自:https://blog.csdn.net/Adusts/a ...
- Codeforces Beta Round #93 (Div. 2 Only) (Virtual participation)
A 相邻点对距离和*k B (Σ(v/2))/2 C 一直想不到"最优"是怎么体现的,发现y2=y1*(t1-t0)/(t0-t2),就写了1e6的枚举,然而又一些特殊情况没考虑到 ...
- Python之粘包
Python之粘包 让我们基于tcp先制作一个远程执行命令的程序(1:执行错误命令 2:执行ls 3:执行ifconfig) 注意注意注意: res=subprocess.Popen(cmd.deco ...
- Python面向对象之类属性类方法静态方法
类的结构 实例 使用面向对象开发时,第一步是设计类: 当使用 类名() 创建对象时,会自动执行以下操作: 1.为对象在内存中分配空间--创建对象: 2.为对象的属性 设置初始值--初始化方法(init ...
- SpringMVC Controller的返回类型
Controller的三种返回类型中 ModelAndView类型 带数据带跳转页面 String 跳转页面不带数据 void 通常是ajax格式请求时使用 1返回ModelAndView contr ...
- 我们参与投资36Kr股权众筹项目“易途8”的决策过程
背景 中文接机.中文送机.中文包车. 当地玩乐 最大的竞争对手:皇包车,15年9月A轮 其它对手:唐人接等,订单量无法和 皇包车.易途8比. 看好理由 1.旅游行业和境外自由行,是 ...
- bash shell & front-end & auto publish & auto deploy
bash shell & front-end & auto publish & auto deploy $ zip -r apitool-2018-11-22.zip apit ...
- hdu 4431 绝对值之和最小公式
/* 普通的二分不好写,反正我没写出来,这题核心需要求出绝对值最小公式 sum=|x+10|+|x+5|+|x+1|+|x-2|+|x-6|;sumx[1]=-10;sumx[2]=-15;sumx[ ...
- 2018/2/15 ES Beats的学习笔记
Beats其实是几种服务的统称(你也可以把收集到的数据存储到别的数据源,不一定非要ES),这几种服务分别是: 1.PacketBeat 通过抓包的方式来监控一些服务.如:HTTP,DNS,Redis, ...
- [USACO12FEB]附近的牛Nearby Cows
题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into accoun ...