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 ...
 
随机推荐
- 在你的Android手机上运行Linux
			
之前试过许多方法(也就几种),像什么Complete Linux Installer,Debian noroot,利用已有的Linux构造Bootstrap之类,要么就是复杂得要命(调了两天没有调出来 ...
 - 17Spring前置通知
			
1).加入jar包:下载地址 spring-beans-4.1.6.RELEASE.jar commons-logging-1.1.3.jar spring-context-4.1.6.RELEASE ...
 - Android Studio + Genymotion模拟器安装与配置
			
一.Android studio 下载与安装 https://developer.android.google.cn/studio/index.html 进入谷歌官方链接下载Android studi ...
 - mysql 替换数据库字段内容
			
去掉数据库字段单引号 update company_info set company=REPLACE(company,"'","");
 - *** 红包书用法 及 ubuntu全局配置
			
使用教程 http://go.wasai.org/sswiki https://home.maysoul.com/wiki/doku.php?id=shadowsocks ubuntu使用教程 htt ...
 - 利用类装饰器自定制property实现延迟计算
			
class LazyProperty: ''' hello,我是非数据描述符(没有定义__set__,不然是大哥数据描述符了--!) ''' def __init__(self, func): pri ...
 - SQL-Redis使用详细教程
			
一.Redis基础部分: 1.redis介绍与安装比mysql快10倍以上 *****************redis适用场合**************** 1.取最新N个数据的操作 2.排行榜应 ...
 - UvaLive 4872 Underground Cables  (最小生成树)
			
题意: 就是裸的最小生成树(MST), 完全图, 边长是实数. 分析: 算是复习一下MST把 方法一: prim 复杂度(n^2) #include <bits/stdc++.h> usi ...
 - Flask(1):基本示例、配置文件、路由、请求和响应、模板渲染
			
Flask的特点: - pip install flask - 短小精悍.可扩展性强的 web框架 注意:上下文管理机制 - 依赖 wsgi:werkzeug Flask的简单示例: from fla ...
 - NOIP2015提高组D1T3 斗地主
			
问一副排n张,n<=23最少打几次打完,数据组数T<=100. 面向数据编程.. 前30分:乱暴力?没有顺子,把单.对子.炸弹.三张.王炸.三带一判一次即可. 前70分:状压,先预处理哪些 ...