| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 5148 | Accepted: 2150 |
Description
For the sake of simplicity, we model a city as a rectangular grid. An address in the city is denoted by two integers: the street and avenue number. The time needed to get from the address a, b to c, d by taxi is |a - c| + |b - d| minutes. A cab may carry out a booked ride if it is its first ride of the day, or if it can get to the source address of the new ride from its latest,at least one minute before the new ride's scheduled departure. Note that some rides may end after midnight.
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
Source
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;
const int maxn=505;
vector<int>edge[maxn];
bool vis[maxn];
int match[maxn],p;
struct node{
int ho,mi;
int tho,tmi;
int s[2],t[2];
}ride[maxn];
inline int f(int a)
{
return a<0?(-a):a;
}
bool ok(node a,node b)
{
if(a.tho*60+a.tmi+f(a.t[0]-b.s[0])+f(a.t[1]-b.s[1])-b.ho*60-b.mi<=0)
return true;
return false;
}
bool find(int now)
{
int i,v;
for(i=0; i<edge[now].size(); ++i)
if(!vis[v=edge[now][i]])
{
vis[v]=true;
if(match[v]==-1||find(match[v]))
{
match[v]=now;
return true;
}
}
return false;
}
int main()
{
int i,j,m,tmp;
int ca;
scanf("%d",&ca);
while(ca--)
{
scanf("%d",&m);
memset(match,-1,sizeof(match));
for(i=1; i<=m; i++)
{
edge[i].clear();
scanf("%d:%d",&ride[i].ho,&ride[i].mi);
scanf("%d%d%d%d",&ride[i].s[0],&ride[i].s[1],&ride[i].t[0],&ride[i].t[1]);
tmp=f(ride[i].s[0]-ride[i].t[0])+f(ride[i].s[1]-ride[i].t[1]);
ride[i].tmi=(ride[i].mi+tmp+1)%60;
ride[i].tho=(ride[i].mi+tmp+1)/60+ride[i].ho;
}
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
if(ok(ride[i],ride[j]))
edge[i].push_back(j);
int res=0;
for(i=1; i<=m; i++)
{
memset(vis,0,sizeof(vis));
if(find(i)) res++;
}
printf("%d\n",m-res);
}
return 0;
}
382




被折叠的 条评论
为什么被折叠?



