POJ 3216 最小路径覆盖+floyd
| 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 pi, ti 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
#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的更多相关文章
- poj 3216 (最小路径覆盖)
题意:有n个地方,m个任务,每个任务给出地点,开始的时间和完成需要的时间,问最少派多少工人去可以完成所有的任务.给出任意两点直接到达需要的时间,-1代表不能到达. 思路:很明显的最小路径覆盖问题,刚开 ...
- poj2594 (最小路径覆盖 + floyd)
题目链接 http://poj.org/problem?id=2594) 题目大意: 一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过. 最小路径覆盖问题. 分析 ...
- poj 1548(最小路径覆盖)
题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...
- poj2594最小路径覆盖+floyd
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8909 Accepted: 3 ...
- POJ 3216 Repairing Company(最小路径覆盖)
POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...
- POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】
Treasure Exploration Time Limit:6000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
- POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)
<题目链接> 题目大意: 机器人探索宝藏,有N个点,M条边.问你要几个机器人才能遍历所有的点. 解题分析: 刚开始还以为是最小路径覆盖的模板题,但是后面才知道,本题允许一个点经过多次,这与 ...
- POJ 2594 传递闭包的最小路径覆盖
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7171 Accepted: 2 ...
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ...
随机推荐
- Android MimeType的用法和几种类型
关于MIME TYPE描述 多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions)是一个互联网标准,它扩展了电子邮件标准,使其能够支持非ASCII ...
- 一个Json结构对比的Python小工具兼谈编程求解问题
先上代码. jsondiff.py #!/usr/bin/python #_*_encoding:utf-8_*_ import argparse import json import sys rel ...
- php计算两个日期相差 年 月 日
在PHP程序中,很多时候都会遇到处理时间的问题,比如:判断用户在线了多长时间,共登录了多少天,两个帖子发布的时间差或者是不同操作之间的日志记录等等.在文章中,简单地举例介绍了PHP中如何计算两个日期相 ...
- 学习Linux系列--安装Ubuntu
最近学习Linux,使用虚拟机太不方便,于是购买了阿里云最便宜的云主机作为学习设备. 本系列文章记录了个人学习过程的点点滴滴. 学习Linux系列--安装Ubuntu 学习Linux系列--安装软件环 ...
- Android中帧布局-FrameLayout和网格布局-GridLayout
帧布局-FrameLayout 一.概念 帧布局中,容器为每个加入其中的空间创建一个空白的区域(成为一帧).每个空间占据一帧,这些帧会按gravity属性自动对齐. 帧布局的效果是将其中的所有空间叠加 ...
- mysql 插入中文报错: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value...
总结写在前面, 总结: 当Java通过jdbc链接mysql插入中文时,要保证程序可以正常执行,而且插入的中文不会乱码, mysql服务器端,对数据表(不是数据库)的编码设置,要保证是支持中文的,例如 ...
- 执行大量的Redis命令,担心效率问题?用Pipelining试试吧~
参考的优秀文章 Request/Response protocols and RTT 来源 原来,系统中一个树结构的数据来源是Redis,由于数据增多.业务复杂,查询速度并不快.究其原因,是单次查询的 ...
- 安装 phoneGap
npm config set registry http://registry.cnpmjs.org 使用最新版本PhoneGap ,决定使用官方提供的方法安装一次. 官方提供方法有些地方没有提到,因 ...
- zabbix脚本报警
zabbix问端设置: 1,设置报警类型 2.设置用户及媒体类型 send_to 就是zabbix输出的$1,脚本中药发给谁 3.设置触发器和动作 触发器 test.temp_conn (自己写一个简 ...
- PHP-----函数和二进制
递归-----函数本身调用本身.每一个栈中的变量都是独立的,不受外部变量的影响,除非传参.这一点和Js不一样. 在一个php页面中要引用其他的php文件可以使用require,require_once ...