标签:des style blog http color os io strong ar
Description
Input
Output
Sample Input
2 2 08:00 10 11 9 16 08:07 9 16 10 11 2 08:00 10 11 9 16 08:06 9 16 10 11
Sample Output
1 2
今天我又把题目粘过来了, 原因很简单, 我又读错题了 TAT
大意:有n个点,给你一个起始时间,从一个点到另一个点需要的时间是横纵坐标差的绝对值之和, 问需要派出多少cab
分析:最小路径覆盖 = n - 最大匹配
代码:
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <vector> 5 #include <cmath> 6 using namespace std; 7 8 const int maxn = 505; 9 const int INF = 1000000000; 10 11 int n; 12 int vis[maxn]; 13 int Link[maxn]; 14 vector<int> G[maxn]; 15 bool Find(int u) { 16 for(int i = 0; i < G[u].size(); i++) { 17 int v = G[u][i]; 18 if(!vis[v]) { 19 vis[v] = 1; 20 if(Link[v] == - 1 || Find(Link[v])) { 21 Link[v] = u; 22 return true; 23 } 24 } 25 } 26 return false; 27 } 28 29 int solve() { 30 int cnt = 0; 31 memset(Link, -1, sizeof(Link)); 32 for(int i = 1; i <= n; i++) { 33 if(G[i].size()) { 34 memset(vis, 0, sizeof(vis)); 35 if(Find(i)) cnt++; 36 } 37 } 38 return cnt; 39 } 40 41 int a[maxn], b[maxn], c[maxn], d[maxn], t[maxn]; 42 bool check(int i, int j) { 43 if(t[j] - ((fabs(c[i] - a[i]) + fabs(d[i] - b[i]) + t[i]) + fabs(a[j] - c[i]) + fabs(b[j] - d[i])) >= 1) { 44 return true; 45 } 46 return false; 47 } 48 49 int main() { 50 int tt; 51 int x, y; 52 scanf("%d",&tt); 53 while(tt--) { 54 scanf("%d",&n); 55 for(int i = 1; i <= n; i++) { 56 G[i].clear(); 57 scanf("%d:%d",&x,&y); 58 t[i] = x * 60 + y; 59 scanf("%d %d %d %d",&a[i], &b[i], &c[i], &d[i]); 60 } 61 for(int i = 1; i <= n; i++) { 62 for(int j = 1; j <= n; j++) { 63 if(i == j) continue; 64 if(check(i, j)) { 65 G[i].push_back(j); 66 } 67 } 68 } 69 printf("%d\n", n - solve()); 70 } 71 return 0; 72 }
POJ 2060 Taxi Cab Scheme【最小路径覆盖】
标签:des style blog http color os io strong ar
原文地址:http://www.cnblogs.com/zhanzhao/p/3942700.html