1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <vector>
using namespace std; const int maxn = 505; struct node {int a,b,c,d,time;}p[maxn];
vector<int> v[maxn]; int match[maxn],time1[maxn],dis[maxn]; bool vis[maxn]; int n;
int dfs(int u) { for (int i=0; i<v[u].size(); ++i) { int to = v[u][i]; if (!vis[to]) { vis[to] = 1; if (match[to]==-1 || dfs(match[to])) { match[to] = u; return 1; } } } return 0; }
int solve() { int res = 0; memset(match,-1,sizeof match); for (int i=0; i<n; ++i) { memset(vis,0,sizeof vis); res += dfs(i); } return res; }
int main() { freopen("1.in","r",stdin); int times; cin >> times; int h,m; while (times--) { scanf("%d",&n); for (int i=0; i<=n; ++i) v[i].clear(); for (int i=0; i<n; ++i) { scanf("%d:%d %d%d%d%d",&h,&m,&p[i].a,&p[i].b,&p[i].c,&p[i].d); p[i].time = abs(p[i].a-p[i].c) + abs(p[i].b - p[i].d); time1[i] = h*60+m; for (int j=0; j<i; ++j) if (time1[i]-time1[j]>p[j].time + abs(p[i].a-p[j].c) + abs(p[i].b-p[j].d)) v[j].push_back(i); } printf("%d\n",n-solve()); } return 1; }
|