HDU 4109 Instrction Arrangement
来源:互联网 发布:2016网络作家排名 编辑:程序博客网 时间:2024/04/30 15:02
一.原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4109
二.题意:计算机指令之间需要间隔一定的时间,CPU处理指令的时间为1nm,给出指令之间的安全时间,求执行完所有指令的最短时间。
三.思路:
关键路径问题:求在一张有向图中,前面的任务要先执行完才可以执行后面的任务。(其实就是短板效应)。这个算法有2个关键数组:
Ee[]:事件E[i]最早开始时间。(从前往后推,保存大的路径)
El[]:事件E[I]最晚开始时间。(从后往前推,保存小的路径)
如果Ee == El,那么这个是关键事件。
然而这题求个Ee,然后扫一遍求最大的就完了。
四.代码:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <queue>#include <vector>using namespace std;const int MAX_SIZE = 1000, INF = 0x3f3f3f3f;struct node{ int v, weight;};int cnt[MAX_SIZE], nodeNum, edgeNum, Ee[MAX_SIZE];vector <node> graph[MAX_SIZE];void initGraph(){ int i; for(i = 0; i < nodeNum; i++) graph[i].clear(); memset(cnt, 0, sizeof(cnt)); memset(Ee, 0, sizeof(Ee));}void TopoSort(){ int i, cur; queue <int> que; for(i = 0; i < nodeNum; i++) if(0 == cnt[i]){ que.push(i); Ee[i] = 1; } while(!que.empty()){ cur = que.front(); que.pop(); for(i = 0; i < graph[cur].size(); i++){ if(0 == --cnt[graph[cur][i].v]) que.push(graph[cur][i].v); Ee[graph[cur][i].v] = max(Ee[cur] + graph[cur][i].weight, Ee[graph[cur][i].v]); } }}int main(){ //freopen("in.txt", "r", stdin); int i, j, u, res; node temp; while(cin>>nodeNum>>edgeNum){ initGraph(); for(i = 0; i < edgeNum; i++){ cin>>u>>temp.v>>temp.weight; graph[u].push_back(temp); cnt[temp.v]++; } TopoSort(); res = -1; for(i = 0; i < nodeNum; i++) res = max(Ee[i], res); cout<<res<<endl; } return 0;}
0 0
- HDU 4109 Instrction Arrangement
- Hdu 4109 Instrction Arrangement
- HDU 4109 Instrction Arrangement
- HDU 4109 Instrction Arrangement
- HDU 4109 Instrction Arrangement
- hdu 4109 Instrction Arrangement(关键路径)
- (关键路径)HDU 4109 Instrction Arrangement
- HDU 4109 Instrction Arrangement(差分约束)
- hdu 4109 Instrction Arrangement (差分约束)
- 【hdoj 4109】Instrction Arrangement
- hdu 4109 Instrction Arrangement 拓扑排序 关键路径
- HDU 4109 Instrction Arrangement 差分约束系统
- hdu 4109 Instrction Arrangement 拓扑排序 关键路径
- HDU 4109 Instrction Arrangement(差分约束系统)
- HDU 4109 Instrction Arrangement拓扑排序 关键路径模板
- hdu 4109 Instrction Arrangement 拓扑排序/觉得更像BFS
- Instrction Arrangement (hdu 4109 差分约束)
- hdu 4109 Instrction Arrangement【DAG图上的最长路】
- 第七周项目3多文件组织程序
- delete析构的调用
- 4.11搭建网站的两个小问题
- iOS中RunLoop机制的探索
- CSU-1715 Positive Con Sequences(模拟分四种情况 )From湖南省多校对抗赛E题(2016.03.27)
- HDU 4109 Instrction Arrangement
- overfeat 测试
- JavaScript中数组和字符串的方法以及互相转换
- Warning C4819
- C++作业3
- windows/linux进程控制实验
- PSobj [2] 图片动漫处理 及 速写处理
- BitmapShader将图片转化为圆形图片
- VS2012通过makefile编译OpenGL红宝书的示例代码