其他分享
首页 > 其他分享> > POJ2060 Taxi Cab Scheme 出租车 NWERC2004

POJ2060 Taxi Cab Scheme 出租车 NWERC2004

作者:互联网

传送


题面:有\(m\)位客人从城市的不同位置出发,到达各自目的地。已知每人的出发时间、地点和目的地,用尽量少的出租车送他们,使得每次出租车接客人时,至少能提前一分钟到达他所在的位置。注意,为了满足这一条件,要么这位客人是这辆出租车接送的第一个人,要么在接送完上一个客人后,有足够的时间从上一个目的地开到这里。为简单起见,假定城区是网格型的,地址用坐标\((x,y)\)表示。出租车从\((x_1, y_1)\)处到\((x_2,y_2)\)处需要行驶\(|x_1 -x_2| + |y_1 −y_2|\)分钟。


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<queue>
#include<assert.h>
#include<ctime>
using namespace std;
#define enter puts("") 
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
#define forE(i, x, y) for(int i = head[x], y; ~i && (y = e[i].to); i = e[i].nxt)
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 505;
const int maxe = 3e5 + 5;
In ll read()
{
	ll ans = 0;
	char ch = getchar(), las = ' ';
	while(!isdigit(ch)) las = ch, ch = getchar();
	while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
	if(las == '-') ans = -ans;
	return ans;
}
In void write(ll x)
{
	if(x < 0) x = -x, putchar('-');
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}

char s[6];
int n;
struct Edge
{
	int nxt, to;
}e[maxe];
int head[maxn], ecnt = -1;
In void addEdge(int x, int y)
{
	e[++ecnt] = (Edge){head[x], y};
	head[x] = ecnt;
}
struct Node
{
	int tim, tim2, xs, ys, xe, ye;
	In void calc(char* s)
	{
		tim = ((s[0] - '0') * 10 + (s[1] - '0')) * 60;
		tim += (s[3] - '0') * 10 + (s[4] - '0');
		tim2 = abs(xs - xe) + abs(ys - ye);
	}
}t[maxn];
In bool check(int i, int j)
{
	return t[i].tim2 + abs(t[i].xe - t[j].xs) + abs(t[i].ye - t[j].ys) < t[j].tim - t[i].tim;
}

bool vis[maxn];
int lft[maxn];
In bool dfs(int now)
{
	forE(i, now, v) if(!vis[v])
	{
		vis[v] = 1;
		if(!lft[v] || dfs(lft[v])) {lft[v] = now; return 1;}
	}
	return 0;
}
In int hung()
{
	int ret = 0; Mem(lft, 0);
	for(int i = 1; i <= n; ++i)
	{
		Mem(vis, 0);
		if(dfs(i)) ++ret;
	}
	return ret;
}

int main()
{
	int T = read();
	while(T--)
	{
		Mem(head, -1), ecnt = -1;
		n = read();
		for(int i = 1; i <= n; ++i) 
		{
			scanf("%s", s);
			t[i].xs = read(), t[i].ys = read(), t[i].xe = read(), t[i].ye = read();
			t[i].calc(s);
		}
		for(int i = 1; i <= n; ++i)
			for(int j = i + 1; j <= n; ++j) 
				if(check(i, j)) addEdge(i, j);	
		write(n - hung()), enter;
	}
	return 0;
}

标签:Taxi,10,ch,int,POJ2060,lft,NWERC2004,include,define
来源: https://blog.51cto.com/u_15234622/2831620