陈越何欣铭老师数据结构PTA08-图8 How Long Does It Take
题目:
08-图8 How Long Does It Take (25分)
Given the relations of all the activities of a project, you are supposed to find the earliest completion time of the project.
Input Specification:
Each input file contains one test case. Each case starts with a line containing two positive integers NNN (≤100\le 100≤100), the number of activity check points (hence it is assumed that the check points are numbered from 0 to N−1N-1N−1), and MMM, the number of activities. Then MMM lines follow, each gives the description of an activity. For the i
-th activity, three non-negative numbers are given: S[i]
, E[i]
, and L[i]
, where S[i]
is the index of the starting check point, E[i]
of the ending check point, and L[i]
the lasting time of the activity. The numbers in a line are separated by a space.
Output Specification:
For each test case, if the scheduling is possible, print in a line its earliest completion time; or simply output "Impossible".
Sample Input 1:
9 12
0 1 6
0 2 4
0 3 5
1 4 1
2 4 1
3 5 2
5 4 0
4 6 9
4 7 7
5 7 4
6 8 2
7 8 4
Sample Output 1:
18
Sample Input 2:
4 5
0 1 1
0 2 2
2 1 3
1 3 4
3 2 5
Sample Output 2:
Impossible
思路:只可意会不可言传。基本和陈越老师讲的例题意思一样。
代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MaxN 100+10
typedef struct line *queue;
int indegree[MaxN]={0};
int maxtime[MaxN];
int symbol[MaxN]={0};
struct act
{int *outact;int *outtime;int now;
}a[MaxN];
struct line
{int star;int end;int *Element;
};
//
queue CreateQ(int Size)
{queue q;q=(queue)malloc(sizeof(struct line));q->star=0;q->end=0;q->Element=(int *)malloc(sizeof(int)*(Size+1));return q;
}
void InsertQ(int X,queue q)
{q->Element[q->end++]=X;
}
int DeleteQ(queue q)
{return q->Element[q->star++];
}
int IsEmptyQ(queue q)
{return q->star==q->end;
}
//
void Initialize(int N)
{int i;for(i=0;i<=N;i++){a[i].now=0;a[i].outact=(int *)malloc(sizeof(int)*(N+1));a[i].outtime=(int *)malloc(sizeof(int)*(N+1));}
}
int main()
{int N,M;queue q;memset(maxtime,0,sizeof(maxtime));scanf("%d%d",&N,&M);Initialize(N);q=CreateQ(N);int i;for(i=1;i<=M;i++){int star,end,time;scanf("%d%d%d",&star,&end,&time);a[star].outact[a[star].now]=end;a[star].outtime[a[star].now++]=time;indegree[end]++;}for(i=0;i<N;i++)if(indegree[i]==0){InsertQ(i,q);symbol[i]=1;}int cnt=0;int X=-1; while(!IsEmptyQ(q)){X=DeleteQ(q);cnt++;for(i=0;i<a[X].now;i++){indegree[a[X].outact[i]]--;if(indegree[a[X].outact[i]]==0)InsertQ(a[X].outact[i],q);if(maxtime[a[X].outact[i]]<maxtime[X]+a[X].outtime[i])maxtime[a[X].outact[i]]=maxtime[X]+a[X].outtime[i];} }if(cnt!=N)printf("Impossible");else{int max=-1;for(i=0;i<N;i++)if(maxtime[i]>max)max=maxtime[i]; printf("%d",max);} return 0;
}
陈越何欣铭老师数据结构PTA08-图8 How Long Does It Take相关推荐
- 数据结构与算法(陈越)(学习笔记)(更新ing)
数据结构(陈越) 一.数据结构(计算运行时间) #include<stdio.h> #include<time.h> #include<math.h> clock_ ...
- 【2020-MOOC-浙江大学-陈越、何钦铭-数据结构】春期中考试(附每一个题目的详细解析)
文章目录 〇.前言 一.判断题 二.选择题 三.程序填空题 总结 〇.前言 这周开始了[MOOC-浙江大学-陈越.何钦铭-数据结构]的期中考试,感觉有点难,可能是我才学了一个月不到的原因??? 一.判 ...
- 数据结构(陈越、何钦铭)学习笔记
本系列文章为浙江大学陈越.何钦铭数据结构学习笔记,系列文章链接如下: 文章目录 一.基本概念 二.线性结构 三.树 四.图 五.排序 六.散列查找 一.基本概念 数据结构基础:P1-基本概念 数据结构 ...
- 【2020-MOOC-浙江大学-陈越、何钦铭-数据结构】树和堆(第五周的笔记和编程作业)
文章目录 〇.前言 一.堆 二.堆的基本操作 三.哈夫曼树 四.集合及运算 五.堆中的路径 六.课后题 1.05-树7 堆中的路径 (25分) 2.05-树8 File Transfer (25分) ...
- 浙江大学MOOC数据结构-陈越、何钦铭 编程练习题(第一讲)
浙江大学MOOC数据结构-陈越.何钦铭 编程练习题(第一讲) 编程题目 编程说明 编程环境:Code::Blocks 编程语言:C 注:第一题未在程序平台运行,仅在编程环境运行 第一题代码 #incl ...
- 《数据结构》严蔚敏与陈越伪代码总结
1 //陈 2 typedef struct LNode *List;3 struct LNode{4 int Data[MaxSize];//如果放多个元素,这个可改为指针,在初始化中指向数组 5 ...
- 数据结构与算法(陈越版)第五讲 (树下)树的应用——集合及其运算
数据结构与算法(陈越版)第五讲 (树下)树的应用--集合及其运算 一.集合的表示 1.1.集合的表示 1.2.集合的储存 二.集合的运算 2.1查找以及普通并 2.2按照秩的合并算法 2.3路径压缩优 ...
- 陈越数据结构_第一周
陈越数据结构_第一周 1. 最大子列和问题 是第一周最后讲到的4种算法的实验题,属于基本要求,一定要做: 题目见PAT 输入样例: 6 -2 11 -4 13 -5 -2 输出样例: 20 1.1 解 ...
- 浙江大学 数据结构 陈越姥姥 百度网盘
浙江大学 数据结构 陈越姥姥 百度网盘 mark 不用再费力找了,这套教程刷了好几遍. 数据结构的重要性,怎么说都不为过 我去,csdn抽什么风,不允许发链接, 链接: https://pan.bai ...
- 陈越《数据结构》第一讲 基本概念
陈越<数据结构>第一讲 基本概念 1什么是数据结构 1.1 引子 例子:如何在书架上摆放图书? 随便放: 按照书名的拼音字母顺序排放: 把书架划分成几块区域,每块区域指定摆放某种类别的图书 ...
最新文章
- 王坚十年前的坚持,才有了今天世界顶级大数据计算平台MaxCompute...
- java期_java日期 时间
- Android Studio 选项菜单和动画结合_谷歌准备为Android增加像iOS一样的功能
- 卷积神经网络数学原理解析
- 大数据笔记2019.5.7
- python测试开发自学教程-【光荣之路】Python全栈测试开发课程
- win7构建成功helloworld驱动、WDF驱动中KMDF与UMDF区别
- raid卡缓存对硬盘性能_Mac Pro 2019加装2.5英寸机械硬盘方案
- Effective Java之基本类型优于装箱类型(四十九)
- iris数据_Kaggle 数据可视化课程5
- 欢乐纪中B组周五模拟赛【2019.3.8】
- QT QTransform与QMatrix 有啥区别?
- python练习题-day2
- mysql查询2个isbn数据,数据库实验二 数据查询
- 《深度探索C++对象模型》调用虚函数
- 弱密码校验_TomCat8 弱密码上传getshell
- Disruptor 分析
- mysql 两表关联更新sql
- Java 实现图书管理系统
- 无线通信与编码_MATLAB仿真实现Jakes信道模型_含仿真代码_瑞利衰落信道模型
热门文章
- 通达OA 小飞鱼OA实施法:以项目管理的方式来推进工作流设计项目实施
- 多线程概念以及线程同步
- 嵌入式面试经验分享1——应届生
- javascript中function前面加(/!/+/-/~的含义
- echart-pie
- microusb贴片 ad封装_diy从pcb到焊接,到程序调试,真正意思上的diy机械键盘pcb由ad绘制...
- css3 模糊渐变,css3实现背景色渐变linear-gradient()
- arm架构下spinlock原理 (代码解读)
- 解决训练时显存不断增大问题
- 电子计算机用户网络新词秀,网络新词的研究