UVALive - 7368 Airports DAG图的最小路径覆盖
题目链接:
http://acm.hust.edu.cn/vjudge/problem/356788
Airports
Time Limit: 3000MS
#### 问题描述
> An airline company offers flights out of n airports, conveniently labeled
> from 1 to n. The flight time tij from airport i to airport j is known for
> every i and j. It may be the case that tij ̸= tji, due to things like wind
> or geography. Upon landing at a given airport, a plane must be inspected
> before it can be flown again. This inspection time pi
> is dependent only
> on the airport at which the inspection is taking place and not where the
> previous flight may have originated.
> Given a set of m flights that the airline company must provide, determine
> the minimum number of planes that the company needs to purchase. The airline may add
> unscheduled flights to move the airplanes around if that would reduce the total number of planes
> needed.
#### 输入
> The input file contains several test cases, each of them as described below.
> The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 500). The next
> line contains n space-separated integers p1, . . . , pn (0 ≤ pi ≤ 106
> ).
> Each of the next n lines contains n space-separated integers. The j-th integer in line i + 2 is tij
> (0 ≤ tij ≤ 106
> ). It is guaranteed that tii = 0 for all i. However, it may be the case that tij ̸= tji when
> i ̸= j.
> Each of the next m lines contains three space-separated integers, si
> , fi
> , and ti (1 ≤ si
> , fi ≤ n,
> si ̸= fi
> , 1 ≤ ti ≤ 106
> ), indicating that the airline company must provide a flight that flies out from
> airport si at exactly time ti
> , heading directly to airport fi
> .
#### 输出
> For each test case, print, on a single line, a single integer indicating the minimum number of planes the
> airline company must purchase in order to provide the m requested flights.
#### 样例
> **sample input**
> 2 2
> 1 1
> 0 1
> 1 0
> 1 2 1
> 2 1 1
> 2 2
> 1 1
> 0 1
> 1 0
> 1 2 1
> 2 1 3
> 5 5
> 72 54 71 94 23
> 0 443 912 226 714
> 18 0 776 347 810
> 707 60 0 48 923
> 933 373 881 0 329
> 39 511 151 364 0
> 4 2 174
> 2 1 583
> 4 3 151
> 1 4 841
> 4 3 993
>
> **sample output**
> 2
> 1
> 3
题意
给你一个有向图,有边权和点权,边权代表从u飞到v所需时间,点权p[i]表示如果飞机到达i点之后还要再起飞,那就需要p[i]时间的修整时间。
现在给你m趟航班要飞,每趟航班(u,v,t)表示从u飞到v,并且在u点的起飞时间是t。现在问你用最少的飞机跑完所有的航班。
题解
我们对每趟航班建一个点,如果飞机跑完一趟航班之后还能去跑另一趟航班,我们就连一条有向边,明显这样建出来的图是偏序图,也就是DAG,然后我们对这图跑一遍最小路径覆盖就可以了。
代码
#include<map>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define M (l+(r-l)/2)
#define bug(a) cout<<#a<<" = "<<a<<endl
using namespace std;
typedef __int64 LL;
const int maxn=555;
const int INF=0x3f3f3f3f;
int n,m;
int p[maxn];
int mat[maxn][maxn],f[maxn][maxn];
vector<int> G[maxn];
pair<int,int> a[maxn],b[maxn];
int vis[maxn],lef[maxn];
int match(int u){
for(int i=0;i<G[u].size();i++){
int v=G[u][i];
if(!vis[v]){
vis[v]=1;
if(lef[v]==-1||match(lef[v])){
lef[v]=u;
return true;
}
}
}
return false;
}
int main() {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&p[i]);
//把点权直接合并到边权上
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&mat[i][j]);
if(i!=j) mat[i][j]+=p[j];
}
}
//预处理出最短路,用于判断两趟航班能不能用一架飞机跑
memcpy(f,mat,sizeof(mat));
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
}
}
}
//存每趟航班的两个属性
for(int i=1;i<=m;i++){
int u,v,t;
scanf("%d%d%d",&u,&v,&t);
a[i]=mkp(u,t);
b[i]=mkp(v,t+mat[u][v]);
}
//判断飞机跑完航班i,能不能继续飞航班j
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
if(i!=j&&b[i].Y+f[b[i].X][a[j].X]<=a[j].Y){
G[i].push_back(j);
}
}
}
//DAG的最小路径覆盖
memset(lef,-1,sizeof(lef));
int ans=0;
for(int i=1;i<=m;i++){
memset(vis,0,sizeof(vis));
if(match(i)) ans++;
}
ans=m-ans;
printf("%d\n",ans);
return 0;
}
Notes
最小路径覆盖只能跑没有交叉的,比如1->2->3,4->2->5,这样有交叉的就会出问题,不过可以在建图的时候处理出1->2->3,4->5这样的东西,否则会出问题。
UVALive - 7368 Airports DAG图的最小路径覆盖的更多相关文章
- poj 2060 Taxi Cab Scheme(DAG图的最小路径覆盖)
题意: 出租车公司有M个订单. 订单格式: hh:mm a b c d 含义:在hh:mm这个时刻客人将从(a,b)这个位置出发,他(她)要去(c,d)这个位置. 规定1:从(a,b) ...
- POJ 1442 Air Raid(DAG图的最小路径覆盖)
题意: 有一个城镇,它的所有街道都是单行(即有向)的,并且每条街道都是和两个路口相连.同时已知街道不会形成回路. 可以在任意一个路口放置一个伞兵,这个伞兵会顺着街道走,依次经过若干个路口. 问最少需要 ...
- hdu1151 Air Raid,DAG图的最小路径覆盖
点击打开链接 有向无环图的最小路径覆盖 = 顶点数- 最大匹配 #include <queue> #include <cstdio> #include <cstring& ...
- 有向无环图(DAG)的最小路径覆盖(转)
DAG的最小路径覆盖 定义:在一个有向图中,找出最少的路径,使得这些路径经过了所有的点. 最小路径覆盖分为最小不相交路径覆盖和最小可相交路径覆盖. 最小不相交路径覆盖:每一条路径经过的顶点各不相同.如 ...
- 有向无环图(DAG)的最小路径覆盖
DAG的最小路径覆盖 定义:在一个有向图中,找出最少的路径,使得这些路径经过了所有的点. 最小路径覆盖分为最小不相交路径覆盖和最小可相交路径覆盖. 最小不相交路径覆盖:每一条路径经过的顶点各不相同.如 ...
- Air Raid POJ - 1422 【有向无环图(DAG)的最小路径覆盖【最小不相交路径覆盖】 模板题】
Consider a town where all the streets are one-way and each street leads from one intersection to ano ...
- hdu - 1151 Air Raid(有向无环图的最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 在一个城市里有n个地点和k条道路,道路都是单向的,并且不存在环.(DAG) 现在伞兵需要去n个地点视察,伞 ...
- 训练指南 UVALive - 3126(DAG最小路径覆盖)
layout: post title: 训练指南 UVALive - 3126(DAG最小路径覆盖) author: "luowentaoaa" catalog: true mat ...
- UVAlive3126 Taxi Cab Scheme(DAG的最小路径覆盖)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32568 [思路] DAG的最小路径覆盖. 将每个人看做一个结点,如 ...
随机推荐
- 360提供的SQL防注入
<?php class sqlsafe { private $getfilter = "'|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\ ...
- PHP 实现下载文件到本地
只需要在php文件中设置请求头就可以了,创建download.php文件,代码如下: $fileName = $_GET['filename']; //得到文件名 header( "Cont ...
- 基于jQuery打造的选项卡向上弹出jquery焦点图切换特效
基于jQuery打造的选项卡向上弹出jquery焦点图切换特效 鼠标经过标题栏,会出现层特效向上滑动,并且在同时进行幻灯片切换,效果十分不错. 有兴趣的童鞋可以下载看看,在IE6方面兼容性也不错,只有 ...
- PHP mysql 事务处理实例
事务是必须满足4个条件(ACID):原子性(Autmic).一致性(Consistency).隔离性(Isolation).持久性(Durability) 原子性(Autmic):事务在执行性,要做到 ...
- shopnc二次开发(一)
---恢复内容开始--- 以前没有怎么接触过shopnc,感觉界面挺漂亮的,不过后来自己需要开发一个电商系统,就顺便参考了下,感觉构架垃圾的一塌糊涂.不过平时做这个系统二次开发的业务比较多,所以简单的 ...
- jquery 点击页面其他地方实现隐藏菜单功能
1.给页面文档添加一个点击事件函数,在函数内实现隐藏菜单功能. $('html').click(function(){//Hide the menus if visible});//用$(docume ...
- linux下的mount命令的用法详解
挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式:mount [-t vfstype] [-o option ...
- 小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载四(场景切换)
作为一款真正有使用价值的应用,首先应该至少有两个页面,通过页面的切换来实现更多的交互.比如手机人人网,打开以后先是进入登录页面,登录后会有新鲜事,然后拉开左边的面板,能看到相册.悄悄话.应用之类的其他 ...
- Moses manual 中Basline System 2.3.4节用IRSTLM创建语言模型的命令有误
手册里写到: ~/irstlm/bin/compile-lm \ --text yes \ news-commentary-v8.fr-en.lm.en.gz \ news-commentary-v8 ...
- 一步一步实现Linux设备驱动的Helloworld模块
学了那么多程序语言,总是有一个Hello world开头,不禁感叹Hello world的强大.呵呵,废话少说,咋们的故事当然要从这个Hello world开始. 先查看自己OS使用的内核版本[don ...