TCHS-8-1000

Problem Statement

     When scheduling tasks to be executed by a person, it is sometimes the case that when one task is completed, a later task suddenly becomes more important. In these situations, it is said that the later task is a 'Supertask' of the completed one.

In addition, when a task reaches a certain level of importance, it must be executed immediately. Each task is initially given a priority of 0. Whenever a task is completed, the priority of its Supertask increases by 1. If at some moment one of the tasks has a priority of 2, and has not been previously executed, it must be executed immediately. If no remaining task has a priority of 2, a single unexecuted task of your choice must be executed (you can not wait and must execute one of them).

You have been given N tasks (referenced by numbers 0 to N-1) that must be executed. All of these tasks (with the exception of the last) have a single Supertask, and you are guaranteed that the reference number of a task will always be lower than the reference number of its Supertask. The last task has no supertask, instead the number -1 is used. You also wish to execute the last task (with reference number N-1) as late as possible. Every task takes one minute to complete execution. Given the supertasks for each task, return the latest time (in minutes) that the last task can be started, if you start executing tasks at time 0.

You will be given the supertasks as a int[] supertasks, where element i of supertasks contains the reference number of the supertask for task i.

Definition

    
Class: PendingTasks
Method: latestProcess
Parameters: int[]
Returns: int
Method signature: int latestProcess(int[] supertasks)
(be sure your method is public)
    
 

Notes

- If a task is executed after its Supertask, then its execution has no bearing on the priority of the Supertask.
- Tasks can only be executed once

Constraints

- supertasks will contain between 1 and 50 elements, inclusive
- Element i of supertasks will be between i + 1 and (number of elements in supertasks - 1), inclusive, except the last element of supertasks, which will be -1.

Examples

0)  
    
{4,4,4,4,-1}
Returns: 2
The final task is a supertask of all other tasks. Whenever you finish any two of first four tasks, the priority of the last will have risen from 0 to 2, so it must execute immediately. This happens after two tasks, so the latest it can start is after two minutes.
1)  
    
{1,2,3,4,-1}
Returns: 4
You can do the tasks in order, putting the final task last, starting it at the fourth minute.
2)  
    
{-1}
Returns: 0
The final task is also the only task, so it must be executed immediately.
3)  
    
{6,6,6,7,7,7,8,8,-1}
Returns: 7
We have the following tree:
      8
   /     \
  6       7
/ | \   / | \
0 1 2   3 4 5
We can not complete all of tasks 0 to 7 before task 8 because:
a) one of tasks 0, 1, 2 must be completed after task 6.
b) one of tasks 3, 4, 5 must be completed after task 7.
c) task 8 must be started as soon as both 6 and 7 are finished - so one of 0 to 5 will not be completed at that moment.
One of the possible orderings which starts the final task at the 7th minute is the following: 0, 1, 6, 2, 3, 4, 7, 8.
import static java.lang.Math.max;
import java.util.*;

public class PendingTasks {

	final int N = 60;
	int[][] dp = new int[N][3];
	List<Integer>[] g = new ArrayList[N];
	int n;
	
	public int latestProcess(int[] parents) {
		n = parents.length;
		for (int i = 0; i < n; i++)
			g[i] = new ArrayList<Integer>();
		for (int i = 0; i < n - 1; i++)
			g[parents[i]].add(i);
		for (int i = 0; i < n; i++) {
			int sum = 0, dist = 0;
			for (int j = 0; j < g[i].size(); j++) {
				int u = g[i].get(j);
				sum += dp[u][0];
				dist = max(dist, dp[u][2] - dp[u][0]);
			}
			dp[i][0] = sum + dist;
			dist = 0;
			dp[i][1] = sum + 1;
			for (int j = 0; j < g[i].size(); j++) {
				int u = g[i].get(j);
				dist = max(dist, dp[u][2] - dp[u][0]);
				for (int k = 0; k < g[i].size(); k++)
					if (k != j) {
						int v = g[i].get(k);
						dist = max(dist, dp[u][2]-dp[u][0]+dp[v][1]-dp[v][0]);
					}
			}
			dp[i][1] += dist;
			dp[i][2] = 1;
			for (int j = 0; j < g[i].size(); j++) {
				int u = g[i].get(j);
				dp[i][2] += dp[u][2];
			}
		}
		return dp[n-1][1] - 1;
	}
	
}

 

# 高校智慧校园解决方案摘要 智慧校园解决方案是针对高校信息化建设的核心工程,旨在通过物联网技术实现数字化校园的智能化升级。该方案通过融合计算机技术、网络通信技术、数据库技术和IC卡识别技术,初步实现了校园一卡通系统,进而通过人脸识别技术实现了更精准的校园安全管理、生活管理、教务管理和资源管理。 方案包括多个管理系统:智慧校园管理平台、一卡通卡务管理系统、一卡通人脸库管理平台、智能人脸识别消费管理系统、疫情防控管理系统、人脸识别无感识别管理系统、会议签到管理系统、人脸识别通道管理系统和图书馆对接管理系统。这些系统共同构成了智慧校园的信息化基础,通过统一数据库和操作平台,实现了数据共享和信息一致性。 智能人脸识别消费管理系统通过人脸识别终端,在无需接触的情况下快速完成消费支付过程,提升了校园服务效率。疫情防控管理系统利用热成像测温技术、视频智能分析等手段,实现了对校园人员体温监测和疫情信息实时上报,提高了校园公共卫生事件的预防和控制能力。 会议签到管理系统和人脸识别通道管理系统均基于人脸识别技术,实现了会议的快速签到和图书馆等场所的高效通行管理。与图书馆对接管理系统实现了一卡通系统与图书馆管理系统的无缝集成,提升了图书借阅的便捷性。 总体而言,该智慧校园解决方案通过集成的信息化管理系统,提升了校园管理的智能化水平,优化了校园生活体验,增强了校园安全,并提高了教学和科研的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值