ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

POJ2060 Taxi Cab Scheme 出租车 NWERC2004

2021-05-17 09:05:09  阅读:188  来源: 互联网

标签:Taxi 10 ch int POJ2060 lft NWERC2004 include define


传送


题面:有\(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://www.cnblogs.com/mrclr/p/14775634.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有