hdu 4109 Instrction Arrangement(关键路径)
来源:互联网 发布:新速特软件站怎么下载 编辑:程序博客网 时间:2024/05/18 02:27
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25063
Instrction Arrangement
Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u
Description
Ali has taken the Computer Organization and Architecture course this term. He learned that there may be dependence between instructions, like WAR (write after read), WAW, RAW.
If the distance between two instructions is less than the Safe Distance, it will result in hazard, which may cause wrong result. So we need to design special circuit to eliminate hazard. However the most simple way to solve this problem is to add bubbles (useless operation), which means wasting time to ensure that the distance between two instructions is not smaller than the Safe Distance.
The definition of the distance between two instructions is the difference between their beginning times.
Now we have many instructions, and we know the dependent relations and Safe Distances between instructions. We also have a very strong CPU with infinite number of cores, so you can run as many instructions as you want simultaneity, and the CPU is so fast that it just cost 1ns to finish any instruction.
Your job is to rearrange the instructions so that the CPU can finish all the instructions using minimum time.
If the distance between two instructions is less than the Safe Distance, it will result in hazard, which may cause wrong result. So we need to design special circuit to eliminate hazard. However the most simple way to solve this problem is to add bubbles (useless operation), which means wasting time to ensure that the distance between two instructions is not smaller than the Safe Distance.
The definition of the distance between two instructions is the difference between their beginning times.
Now we have many instructions, and we know the dependent relations and Safe Distances between instructions. We also have a very strong CPU with infinite number of cores, so you can run as many instructions as you want simultaneity, and the CPU is so fast that it just cost 1ns to finish any instruction.
Your job is to rearrange the instructions so that the CPU can finish all the instructions using minimum time.
Input
The input consists several testcases.
The first line has two integers N, M (N <= 1000, M <= 10000), means that there are N instructions and M dependent relations.
The following M lines, each contains three integers X, Y , Z, means the Safe Distance between X and Y is Z, and Y should run after X. The instructions are numbered from 0 to N - 1.
The first line has two integers N, M (N <= 1000, M <= 10000), means that there are N instructions and M dependent relations.
The following M lines, each contains three integers X, Y , Z, means the Safe Distance between X and Y is Z, and Y should run after X. The instructions are numbered from 0 to N - 1.
Output
Print one integer, the minimum time the CPU needs to run.
Sample Input
5 21 2 13 4 1
Sample Output
2
Hint
In the 1st ns, instruction 0, 1 and 3 are executed; In the 2nd ns, instruction 2 and 4 are executed. So the answer should be 2.
百度上的例子:
这时从开始顶点到达完成顶点的所有路径都是关键路径。一个AOE网的关键路径可以不止一条,如图AOE网中有二条关键路径,(v1,v2,v5,v7,v9 ) 和 (v1,v2,v5,v8,v9 )它们的路径长度都是24。如图所示:
本题代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N=1005;int indeg[N],finish[N],n,m;struct node{ int v,cost; struct node *next; node(){ v=cost=0; next=NULL; }}vnode[N];void init(){ memset(indeg,0,sizeof(indeg)); memset(vnode,0,sizeof(vnode)); for(int i=0;i<n;i++) finish[i]=1;}void create(){ node *s; int a,b,c; for(int i=0;i<m;i++){ scanf("%d %d %d",&a,&b,&c); indeg[b]++; s=new node(); s->v=b; s->cost=c; s->next=vnode[a].next; vnode[a].next=s; }}void topo(){ node *p; int v; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(indeg[j]==0){ v=j; break; } } indeg[v]=-1; p=vnode[v].next; while(p){ if(finish[p->v]<finish[v]+p->cost) finish[p->v]=finish[v]+p->cost; indeg[p->v]--; p=p->next; } }}int main(){ //freopen("cin.txt","r",stdin); int ans; while(cin>>n>>m){ init(); ans=0; create(); topo(); for(int i=0;i<n;i++)if(finish[i]>ans)ans=finish[i]; printf("%d\n",ans); } 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
- HDU 4109 Instrction Arrangement
- HDU:4109 Instrction Arrangement (DAG上的最长路/关键路径)
- hdu 4109 Instrction Arrangement (topo+关键路径) (附简单的测试数据)
- HDU 4109 Instrction Arrangement (拓扑or差分约束求关键路径)
- HDU4109 Instrction Arrangement 拓扑排序 关键路径
- HDU4109——Instrction Arrangement(关键路径)
- HDU4109 Instrction Arrangement 拓扑排序求关键路径
- HDU 4109 Instrction Arrangement(差分约束)
- hdu 4109 Instrction Arrangement (差分约束)
- nodejs中如何创建和加载模块
- es all version
- session防止重复提交
- iOS-如何将非ARC的项目转换成ARC项目
- 自动获取短信验证码
- hdu 4109 Instrction Arrangement(关键路径)
- list(链表)常用成员(顺序容器)
- [网狐]前台控制帐号生成
- 45 个非常有用的 Oracle 查询语句
- 菜鸟系列——欧拉函数
- 密码强度等级
- org.apache.log4j.Logger详解
- html5+css3 权威指南阅读笔记(三)---表单及其他新增和改良元素
- Unity GameObject 中文翻译