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 ...
随机推荐
- Hdu 1443 Joseph
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 【转】MarshalAs属性和使用
转载地址:http://blog.sina.com.cn/s/blog_4e4ee8ed0100elou.html [MarshalAs(UnmanagedType.ByValArray, SizeC ...
- Java 多线程处理[全]
http://blog.csdn.net/ghsau/article/details/7421217 Java线程(一):线程安全与不安全 http://blog.csdn.net/ghsau/art ...
- java 将list 按长度分割
public static <T> List<List<T>> splitList(List<T> list, int pageSize) { ...
- Python多进程编程
转自:Python多进程编程 阅读目录 1. Process 2. Lock 3. Semaphore 4. Event 5. Queue 6. Pipe 7. Pool 序. multiproces ...
- [问题2015S03] 复旦高等代数 II(14级)每周一题(第四教学周)
[问题2015S03] 设 \(g(x)=x^n+a_1x^{n-1}+\cdots+a_{n-1}x+a_n\) 是数域 \(\mathbb{K}\) 上的多项式, \(V\) 是 \(\math ...
- iOS 推送
1,推送已至,点通知栏: a)若App在UIApplicationStateActive(活动)状态,调用 //接收到推送消息 - (void)application:(UIApplication * ...
- sourceforge免费空间申请及使用笔记
sourceforge免费空间申请及使用笔记 sourceforge免费空间安装WordPress博客程序 WordPress博客程序安装文件的上传需要使用工具WinSCP. 你需要在FTP地址填写的 ...
- js获取url中的参数值
在博客园看家一片不错的文章:http://www.cnblogs.com/EnderH/p/5398409.html 在这里记下对自己比较有用的三种: 1.正则 function GetQuerySt ...
- phonegap 3.3教程 地理信息api教程
一 准备工作 phonegap3.3的地理信息教程.从零开始,首先要新建一个项目从命令行启动 可以看到这是默认的生成的www目录,在这个目录里是最原始的html文件,编译的时候在根据这里的文件生成an ...