08-图8 How Long Does It Take
原题:
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 N (≤100), the number of activity check points (hence it is assumed that the check points are numbered from 0 to N−1), and M, the number of activities. Then M 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
作者: 陈越
单位: 浙江大学
时间限制: 400ms
内存限制: 64MB
代码长度限制: 16KB
思路:
一道普通的AOE网的题,求关键路径。用临接表实现。
代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXV 101
struct edge
{
int w; //权
int v; //指向的点
};
vector<edge> G[MAXV]; //临接表
int N,M,inDegree[MAXV]={0},ve[MAXV]={0}; //顶点数,边数,入度
int topoSort()
{
int num=0; //入队次数
queue<int> q;
for(int i=0;i<N;i++)
{
if(inDegree[i]==0)
q.push(i); //将度为0的结点入队
}
while(!q.empty())
{
int u=q.front(); //取出队首结点
//cout<<u<<endl;
q.pop();
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i].v;
inDegree[v]--; //入度减1
if(inDegree[v]==0)
q.push(v); //入队
if(ve[u]+G[u][i].w>ve[v]){
ve[v]=ve[u]+G[u][i].w;
}
}
G[u].clear(); //清边,非必需
num++;
}
if(num == N)
return 1;
else
return 0;
}
int main()
{
cin>>N;
cin>>M;
for(int i=0;i<M;i++)
{
int e,s,l;
cin>>e;
cin>>s;
cin>>l;
edge temp={l,s};
G[e].push_back(temp);
inDegree[s]++;
}
if(1==topoSort())
{
int max=0;
for(int i=0;i<N;i++)
{
if(ve[i]>max)
max=ve[i];
}
cout<<max;
}
else
cout<<"Impossible";
return 0;
}
08-图8 How Long Does It Take的更多相关文章
- ISE和Modelsim联合仿真(转)
相信很多人会遇到过这个问题,不知如何让ISE调用Modelsim进行仿真.我也迷糊了不少时间,查查找找,终于弄明白了,所以有了本文,和大家分享一下.我尽量讲得详细点儿,多多上图. 我的环境:Windo ...
- ISE和Modelsim联合仿真(详细步骤讲解)
ISE和Modelsim联合仿真(转) 地址:http://www.cnblogs.com/feitian629/archive/2013/07/13/3188192.html 相信很多人会遇到过这个 ...
- 3ds Max制作客厅场景实例教程
附件系列 (图01) 让我们回顾一下场景:一个房间包括下列一件件家具, 在中间的一张小桌子,在房间的角落的一个小桌子,有一个垃圾桶和一个带镜子的边桌,有一个烛台.还有一个挂钟,窗帘,沙发和带手臂的椅子 ...
- 自定义控件(视图)2期笔记08:自定义控件之 9patch图说明
1. 何为 9patch图 ? 它是一个对png图片做处理的一个工具,能够为我们生成一个"*.9.png"的图片:所谓"*.9.png"这是Androi ...
- Beta阶段第2周/共2周 Scrum立会报告+燃尽图 08
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2389] 版本控制:https://git.coding.net/liuyy08 ...
- 2018.08.29 NOIP模拟 table(拓扑排序+建图优化)
[描述] 给出一个表格,N 行 M 列,每个格子有一个整数,有些格子是空的.现在需要你 来做出一些调整,使得每行都是非降序的.这个调整只能是整列的移动. [输入] 第一行两个正整数 N 和 M. 接下 ...
- ViewPager轮播图
LoopViewPagerLayout无限轮播 项目地址:https://github.com/why168/LoopViewPagerLayout 支持三种动画: 支持修改轮播的速度: 支持修改滑动 ...
- iOS系列 基础篇 08 文本与键盘
iOS系列 基础篇 08 文本与键盘 目录: 1. 扯扯犊子 2. TextField 3. TextView 4. 键盘的打开和关闭 5. 打开/关闭键盘的通知 6. 键盘的种类 7. 最后再扯两句 ...
- 【玩转单片机系列001】 08接口双色LED显示屏驱动方式探索
前些日子,从淘宝上购得一块08接口的双色LED显示屏(打算做个音乐频谱显示器),捣鼓了好几天,终于搞清楚了其控制原理,在这里做个总结,算是备忘吧. 1.LED显示屏的扫描方式 LED显示屏的扫描方式有 ...
- C#+JQuery+.Ashx+百度Echarts实现全国省市地图和饼状图动态数据图形报表的统计
在目前的一个项目中,需要用到报表表现数据,这些数据有多个维度,需要同时表现出来,同时可能会有大量数据呈现的需求,经过几轮挑选,最终选择了百度的echarts作为报表基础类库.echarts功能强大,界 ...
随机推荐
- 【NOIP2015资源+题解】
数据下载(含cena配置文件+一套自己写的代码) 试题下载(pdf版) Day1 T1 Day1 T2 Day1 T3 Day2 T1 Day2 T2 Day3 T3
- LINUX 笔记-mv命令
常用参数: -f :force强制的意思,如果目标文件已经存在,不会询问而直接覆盖 -i :若目标文件已经存在,就会询问是否覆盖 -u :若目标文件已经存在,且比目标文件新,才会更新
- DNS主从服务部署
(1)节点信息 console01 主DNS 192.168.80.3 192.168.10.3 console02 从DNS 192.168.80.4 192.168.10.4 (2)环境部署 # ...
- Ionic3 下拉刷新
参考: http://ionicframework.com/docs/api/components/refresher/Refresher/
- linux学习(七)环境变量、cp、mv、cat,less,more,head,tail
一.环境变量 环境变量其实就是$PATH: [root@iZ25lzba47vZ ~]# echo $PATH /usr/local/nginx/sbin:/usr/local/php/bin:/us ...
- hihocoder 1015题
代码 #include <iostream> #include <string> #include <typeinfo> #include <vector&g ...
- 0_Simple__simpleAtomicIntrinsics + 0_Simple__simpleAtomicIntrinsics_nvrtc
原子操作.并且在静态代码和运行时编译两种条件下使用. ▶ 源代码:静态使用 #ifndef _SIMPLEATOMICS_KERNEL_H_ #define _SIMPLEATOMICS_KERNEL ...
- cloneNode克隆节点在不同浏览器的差异
cloneNode是用于克隆节点的,如果待克隆的节点还有子节点以及自定义属性.添加的有事件,那么克隆时,可以指定是克隆节点本身,还是将其所有子节点信息也克隆进去,这是通过给cloneNode传递一个布 ...
- SQL查询多条不重复记录值简要解析【转载】
转载http://hi.baidu.com/my_favourate/item/3716b0cbe125f312505058eb SQL查询多条不重复记录值简要解析2008-02-28 11:36 以 ...
- JAVAscript学习笔记 js计时器与倒计时 第六节 (原创) 参考js使用表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...