XMU 1040 Schedule 【拓扑排序】

拓扑排序求解任务调度问题
本文介绍了一种使用拓扑排序解决复杂任务调度问题的方法。面对N个任务和M台机器,每个任务需在特定顺序下由各机器处理,文章通过建立任务和机器的依赖关系图,运用拓扑排序算法,高效计算出所有任务完成的最短时间。

 

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 49 

3 1 2 
3 1 2 
1 3 2 

1 2 3 
1 3 2 
1 2 3

Sample Output

495

HINT

 

Source

[ Submit][ Status][ Web Board]

 

 

题目链接:

  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] }

  

  1 /****************************************************
  2     
  3     Author : Coolxxx
  4     Copyright 2017 by Coolxxx. All rights reserved.
  5     BLOG : http://blog.youkuaiyun.com/u010568270
  6     
  7 ****************************************************/
  8 #include<bits/stdc++.h>
  9 #pragma comment(linker,"/STACK:1024000000,1024000000")
 10 #define abs(a) ((a)>0?(a):(-(a)))
 11 #define lowbit(a) (a&(-a))
 12 #define sqr(a) ((a)*(a))
 13 #define mem(a,b) memset(a,b,sizeof(a))
 14 const double EPS=1e-8;
 15 const int J=10000;
 16 const int MOD=100000007;
 17 const int MAX=0x7f7f7f7f;
 18 const double PI=3.14159265358979323;
 19 const int N=304;
 20 using namespace std;
 21 typedef long long LL;
 22 double anss;
 23 LL aans;
 24 int cas,cass;
 25 int n,m,lll,ans;
 26 int t[N][N],a[N][N],b[N][N],d[N][N],in[N][N];
 27 int nex[N][N][2][2];
 28 void tuopu()
 29 {
 30     int i,j,x,y,xx,yy;
 31     mem(d,0);
 32     queue<int>qx,qy;
 33     for(i=1;i<=n;i++)
 34     {
 35         if(!in[i][a[i][1]])
 36         {
 37             d[i][a[i][1]]=t[i][a[i][1]];
 38             qx.push(i);
 39             qy.push(a[i][1]);
 40         }
 41     }
 42     while(!qx.empty())
 43     {
 44         x=qx.front();qx.pop();
 45         y=qy.front();qy.pop();
 46         for(i=0;i<2;i++)
 47         {
 48             xx=nex[x][y][i][0];
 49             yy=nex[x][y][i][1];
 50             if(!x || !y)continue;
 51             d[xx][yy]=max(d[xx][yy],d[x][y]+t[xx][yy]);
 52             if(!--in[xx][yy])
 53             {
 54                 qx.push(xx);
 55                 qy.push(yy);
 56             }
 57         }
 58         ans=max(ans,d[x][y]);
 59     }
 60 }
 61 int main()
 62 {
 63     #ifndef ONLINE_JUDGE
 64     freopen("1.txt","r",stdin);
 65 //    freopen("2.txt","w",stdout);
 66     #endif
 67     int i,j,k,l;
 68     int x,y,z;
 69 //    for(scanf("%d",&cass);cass;cass--)
 70 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
 71 //    while(~scanf("%s",s))
 72     while(~scanf("%d",&n))
 73     {
 74         ans=0;
 75         mem(nex,0);mem(in,0);
 76         scanf("%d",&m);
 77         for(i=1;i<=n;i++)
 78             for(j=1;j<=m;j++)
 79                 scanf("%d",&t[i][j]);
 80         for(i=1;i<=n;i++)
 81             for(j=1;j<=m;j++)
 82                 scanf("%d",&a[i][j]);
 83         for(i=1;i<=m;i++)
 84             for(j=1;j<=n;j++)
 85                 scanf("%d",&b[i][j]);
 86         for(i=1;i<=n;i++)
 87         {
 88             for(j=1;j<m;j++)
 89             {
 90                 nex[i][a[i][j]][0][0]=i,
 91                 nex[i][a[i][j]][0][1]=a[i][j+1];
 92                 in[i][a[i][j+1]]++;
 93             }
 94         }
 95         for(i=1;i<=m;i++)
 96         {
 97             for(j=1;j<n;j++)
 98             {
 99                 nex[b[i][j]][i][1][0]=b[i][j+1],
100                 nex[b[i][j]][i][1][1]=i;
101                 in[b[i][j+1]][i]++;
102             }
103         }
104         tuopu();
105         printf("%d\n",ans);
106     }
107     return 0;
108 }
109 /*
110 //
111 
112 //
113 */
View Code

 

转载于:https://www.cnblogs.com/Coolxxx/p/6691563.html

### 关于XMU OOMALL的理解 XMU OOMALL 可能是指厦门大学(Xiamen University, XMU)的一个在线订单管理系统(Order Management System, OOMALL)。如果将其与引用中的 SpringBoot 和 Java 学生学费支付系统的描述相结合,则可以推测这是一个基于 Web 的应用程序,用于管理学生的学费支付流程以及其他相关功能。 从技术角度来看,Spring Boot 是一种流行的框架,它简化了构建独立的、生产级的 Spring 应用程序的过程。Java 则是一种广泛使用的编程语言,适用于开发企业级应用。结合这些工具和技术栈,可以实现一个高效且可扩展的学生学费支付系统[^1]。 以下是关于如何设计这样一个系统的一些核心概念: #### 1. 用户角色定义 在该系统中存在三种主要用户角色:学生、财务人员以及管理员。每种角色都有特定权限和职责: - **学生**负责完成个人信息注册并执行缴费操作。 - **财务人员**能够查看所有交易记录,并处理异常情况。 - **管理员**则具有最高权限,可用于维护整个平台的安全性和稳定性。 #### 2. 数据库交互机制 每当有新的登录尝试发生时,系统会向数据库写入一条日志记录以跟踪活动状态。这种做法有助于审计目的以及提高安全性水平。 #### 3. 注册模块的重要性 考虑到高校环境中可能存在频繁的人事变动,因此提供灵活便捷的新账户创建途径显得尤为重要。通过允许每位新生自行完成账号设置过程,不仅减少了人工干预需求,还提升了用户体验满意度。 ```java // 示例代码片段展示简单的身份验证逻辑 public boolean authenticateUser(String username, String password){ // 假设这里有一个方法可以从数据库获取密码哈希值 String storedPasswordHash = getUserPasswordFromDatabase(username); if(storedPasswordHash != null && PasswordUtil.matches(password, storedPasswordHash)){ logLoginAttempt(username, true); // 成功登录的日志记录 return true; }else{ logLoginAttempt(username, false); // 失败登录的日志记录 return false; } } ``` 上述代码展示了基本的身份验证函数结构,其中包含了成功或失败情况下均需调用的方法来保存相应的事件数据到后台存储位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值