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功能强大,界 ...
随机推荐
- shell script测试命令(test)
shell script测试命令(test) test命令 检查系统上面某些文件或者相关的属性 常用选项 test -e :检查该文件名是否存在 例:检查/dmtsai是否存在 [root@local ...
- 【转】C语言产生随机数
原文地址:http://www.cnblogs.com/xianghang123/archive/2011/08/24/2152404.html 在C语言中,rand()函数可以用来产生随机数,但是这 ...
- 本地连接 vmware服务器
在本机中装载虚拟机,安装redhat.需要调试使用redhat可以与Windows进行通讯. 分为多步,在此前提下,默认你已经安装好且可以vm 和虚拟机 1:点击虚拟机>设置>添加网络适配 ...
- OSW 快速安装部署
关于在运行Oracle的环境下部署OSW具体好处不再多说,只需要知晓,在日常Oracle定位各类故障,osw的数据可以协助诊断问题.MOS很多文档也多处提到需要osw的监控数据. 一.前期资料准备 1 ...
- JDBC的基本用法
一.编程步骤 1.加载驱动 Class forName("com.mysql.jdbc.Driver"):mysql驱动 Class forName("oralce.jd ...
- 网络基础三 ARP 地址分类 NAT技术
第1章 OSI回顾 1.1 TCP/IP协议族组成 应用层 主机到主机层 互联网层 网络接入层 1.2 总结应用层掌握的协议与端口号对应关系 http(80) telnet(23) ftp(2 ...
- 安装Windows Azure Powershell
本文将介绍如何安装Windows Azure Powershell 1.打开Azure官方链接:https://www.azure.cn/downloads/ 2.按照向导进行安装 3.打开系统自带的 ...
- addEventListener 的事件函数的传递【转载】
addEventListener 参数如下: addEventListener(type, listener[, useCapture]); type,事件名称 listener,事件处理器 useC ...
- HTML学习笔记 CSS表格及轮廓案例 第八节 (原创)参考使用表
#tb, tb1, tr, th, td { border: 5px solid blue; /*加边框*/ padding: 5px; /*内边距*/ } #tb1 { border-collaps ...
- 2017阿里云双11-云服务器ECS优惠活动最强解读和购买指南
本站之前介绍了<爆款云服务器,限时2折起>,这其实是阿里云双11之前的预热活动:四款低配的机型,二折给用户(每个用户限购一台),非常的实惠,有很多阅读了本站文章的用户都一次性购买了三年的. ...