2013
12-26

Taxi Cab Scheme

Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coordination of the cabs in order to pick up the customers calling to get a cab as soon as possible, there is also a need to schedule all the taxi rides which have been booked in advance. Given a list of all booked taxi rides for the next day, you want to minimise the number of cabs needed to carry out all of the rides.

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 &#8722; c| + |b &#8722; 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.

On the first line of the input is a single positive integer N, telling the number of test scenarios to follow. Each scenario begins with a line containing an integer M, 0 < M < 500, being the number of booked taxi rides. The following M lines contain the rides. Each ride is described by a departure time on the format hh:mm (ranging from 00:00 to 23:59), two integers a b that are the coordinates of the source address and two integers c d that are the coordinates of the destination address. All coordinates are at least 0 and strictly smaller than 200. The booked rides in each scenario are sorted in order of increasing departure time.

On the first line of the input is a single positive integer N, telling the number of test scenarios to follow. Each scenario begins with a line containing an integer M, 0 < M < 500, being the number of booked taxi rides. The following M lines contain the rides. Each ride is described by a departure time on the format hh:mm (ranging from 00:00 to 23:59), two integers a b that are the coordinates of the source address and two integers c d that are the coordinates of the destination address. All coordinates are at least 0 and strictly smaller than 200. The booked rides in each scenario are sorted in order of increasing departure time.

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

1
2

POJ-2060-Taxi Cab Scheme

http://poj.org/problem?id=2060

1.一个单独的顶点是一条路径；

2．如果存在一路径p1,p2,……pk，其中p1 为起点，pk为终点，那么在覆盖图中，顶点p1,p2,……pk不再与其它的顶点之间存在有向边．

P’中不在于匹配边时，路径覆盖数为|P|；

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 600
struct node
{
int st,ed;
int a,b,c,d;
}list[N*6];
int map[N][N];
int result[N];
int visit[N];
int n;
int cmp(const void *a,const void *b)
{
return (*(struct node *)a).st-(*(struct node *)b).st;
}
int find(int a)
{
int i;
for(i=1;i<=n;i++)
{
if(!visit[i]&&map[a][i])
{
visit[i]=1;
if(!result[i]||find(result[i]))
{
result[i]=a;
return 1;
}
}
}
return 0;
}
int main()
{
int t,i,j,temp;
int hour,minute,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d:%d %d %d %d %d",&hour,&minute,&list[i].a,&list[i].b,&list[i].c,&list[i].d);
list[i].st=hour*60+minute;
list[i].ed=list[i].st+abs(list[i].a-list[i].c)+abs(list[i].b-list[i].d);
}
qsort(list+1,n,sizeof(list[0]),cmp);
memset(map,0,sizeof(map));
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
temp=abs(list[i].c-list[j].a)+abs(list[i].d-list[j].b);
if(list[i].ed+temp<list[j].st)
map[i][j]=1;
}
ans=0;
memset(result,0,sizeof(result));
for(i=1;i<=n;i++)
{
memset(visit,0,sizeof(visit));
if(find(i))
ans++;
}
printf("%d\n",n-ans);
}
system("pause");
return 0;
}

1. Often We don’t set up on weblogs, but I would like to condition that this established up really forced me individually to do this! considerably outstanding publish

2. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！