Repairing Company
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 6646   Accepted: 1788

Description

Lily runs a repairing company that services the Q blocks in the city. One day the company receives M repair tasks, the ith of which occurs in block pi, has a deadline ti on any repairman’s arrival, which is also its starting time, and takes a single repairman di time to finish. Repairmen work alone on all tasks and must finish one task before moving on to another. With a map of the city in hand, Lily want to know the minimum number of repairmen that have to be assign to this day’s tasks.

Input

The input contains multiple test cases. Each test case begins with a line containing Q and M (0 < Q ≤ 20, 0 < M ≤ 200). Then follow Q lines each with Q integers, which represent a Q × Q matrix Δ = {δij}, where δij means a bidirectional road connects the ith and the jth blocks and requires δij time to go from one end to another. If δij = −1, such a road does not exist. The matrix is symmetric and all its diagonal elements are zeroes. Right below the matrix are M lines describing the repairing tasks. The ith of these lines contains piti and di. Two zeroes on a separate line come after the last test case.

Output

For each test case output one line containing the minimum number of repairmen that have to be assigned.

Sample Input

1 2
0
1 1 10
1 5 10
0 0

Sample Output

2

Source

 
题目意思:
有n个点,m个任务,点之间的权值由矩阵给出,每个任务格式为p、t、d即该任务在p点发生,t时开始,完成任务需要花费的时间d。从一个点到另一个点的花费的时间即为权值。
问完成所有的任务需要多少人。
 
思路:
floyd处理一下,然后当做完i任务后可以做j任务,那么连一条边i->j,最小路径覆盖即可。
 
代码:
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 25
#define M 205 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} struct node{
int p, t, d;
}a[M]; int map[N][N];
int map2[N][N];
vector<int>ve[M];
int from[M];
bool visited[M];
int n; int march(int u){
int i, v;
for(i=;i<ve[u].size();i++){
v=ve[u][i];
if(!visited[v]){
visited[v]=true;
if(from[v]==-||march(from[v])){
from[v]=u;
return ;
}
}
}
return ;
} main()
{
int i, j, k;
int q;
while(scanf("%d %d",&n,&q)==){
if(n==&&q==) break;
for(i=;i<=n;i++){
for(j=;j<=n;j++){
scanf("%d",&map[i][j]);
}
}
for(i=;i<q;i++) scanf("%d %d %d",&a[i].p,&a[i].t,&a[i].d);
for(i=;i<=n;i++){
for(j=;j<=n;j++){
for(k=;k<=n;k++){
if(map[j][i]!=-&&map[i][k]!=-){
if(map[j][k]==-) map[j][k]=map[j][i]+map[i][k];
else map[j][k]=min(map[j][k],map[j][i]+map[i][k]);
}
}
}
}
for(i=;i<q;i++) ve[i].clear();
for(i=;i<q;i++){
for(j=;j<q;j++){
if(map[a[i].p][a[j].p]!=-&&a[i].t+a[i].d+map[a[i].p][a[j].p]<=a[j].t){
ve[i].push_back(j);
// printf("1111\n");
}
}
}
int num=;
memset(from,-,sizeof(from));
for(i=;i<q;i++){
memset(visited,false,sizeof(visited));
if(march(i)) num++;
}
// printf("%d\n",num);
printf("%d\n",q-num);
}
}

POJ 3216 最小路径覆盖+floyd的更多相关文章

  1. poj 3216 (最小路径覆盖)

    题意:有n个地方,m个任务,每个任务给出地点,开始的时间和完成需要的时间,问最少派多少工人去可以完成所有的任务.给出任意两点直接到达需要的时间,-1代表不能到达. 思路:很明显的最小路径覆盖问题,刚开 ...

  2. poj2594 (最小路径覆盖 + floyd)

    题目链接  http://poj.org/problem?id=2594) 题目大意: 一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过. 最小路径覆盖问题. 分析 ...

  3. poj 1548(最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...

  4. poj2594最小路径覆盖+floyd

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8909   Accepted: 3 ...

  5. POJ 3216 Repairing Company(最小路径覆盖)

    POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...

  6. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

  7. POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)

    <题目链接> 题目大意: 机器人探索宝藏,有N个点,M条边.问你要几个机器人才能遍历所有的点. 解题分析: 刚开始还以为是最小路径覆盖的模板题,但是后面才知道,本题允许一个点经过多次,这与 ...

  8. POJ 2594 传递闭包的最小路径覆盖

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 7171   Accepted: 2 ...

  9. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

随机推荐

  1. winform下的智能提示框

    winform下的智能提示框 最近在搞winform的程序,接触到有些可能以后还会用到的功能,所以写到博客园里去,第一可以加深自己的印象,第二可以在以后再遇到同样问题的时候忘记了可以马上回来看看,第三 ...

  2. 企业信息系统——SCM

    供应链是供应商.制造商.仓库.配送中心和渠道商等构成的物流网络.同一个企业可能构成这个网络的不同组成节点,但更多的情况下是由不同的企业构成这个网络中的不同节点.例如,在某条供应链中,某个企业可能即在制 ...

  3. 【笔记】jquery append,appendTo,prepend,prependTo 介绍

    在jquery权威指南里面学习到这一章,很有必要介绍一下里面的内容: 首先是append(content)这个函数: 意思是将内容content加入到所选择的对象内容的后面 例如:$("di ...

  4. LINQ to SQL Count/Sum/Min/Max/Avg Join

    public class Linq { MXSICEDataContext Db = new MXSICEDataContext(); // LINQ to SQL // Count/Sum/Min/ ...

  5. free查看可用缓存

    本篇转自:http://www.cnblogs.com/coldplayerest/archive/2010/02/20/1669949.html 解释一下Linux上free命令的输出. 下面是fr ...

  6. App.xaml

    <Application x:Class="HelloWorld.App" xmlns="http://schemas.microsoft.com/winfx/20 ...

  7. 什么是BOM头

    什么是BOM头? BOM头是放在UTF-8编码的文件的头部的,占用三个字节,用来标识该文件属于UTF-8编码.现在已经有很多软件识别BOM头,但是还有些不能识别BOM头,比如PHP就不能识别BOM头, ...

  8. Unity中Collider和刚体Collider性能对比

    测试方式: 每个对象做大范围正弦移动,创建1000-5000个对象,保证场景分割树的实时更新,并测试帧率 测试脚本: 移动脚本: using UnityEngine; using System.Col ...

  9. php程序员的水平 看看自己属于那个级别的

    文章链接:http://www.oschina.net/question/570781_60150?sort=time&p=4#answers

  10. php : 获取对象的属性名

    方案有多种: 一. 使用 get_object_vars() 方法 缺点: 只能显示 public 的 //只显示public的 var_dump(get_object_vars($test)); 处 ...