题意:有 n 个客人,要从 si 到 ti,每个人有一个出发时间,现在让你安排最少和出租车去接,在接客人时至少要提前一分钟到达客人的出发地点。

析:把每个客人看成一个结点,然后如果用同一个出租车接的话,那么肯定是先接 u 然后再去接 v,也就是有一条边 u->v,画图看的就成知道,这是一个最小路径覆盖的问题。把每个结点拆成 X和 Y 然后如果 u 能连 v,那么就 Xu -> Yv,然后跑一次二分最大匹配,那么答案就是 n - 最大匹配数。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
//#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 10;
const int maxm = 100 + 10;
const int mod = 1000000;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Edge{
int to, next;
};
Edge edge[maxn*maxn];
int head[maxn], cnt; void addEdge(int u, int v){
edge[cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt++;
} bool used[maxn];
int match[maxn]; bool dfs(int u){
used[u] = 1;
for(int i = head[u]; ~i; i = edge[i].next){
int v = edge[i].to, w = match[v];
if(w < 0 || !used[w] && dfs(w)){
match[u] = v;
match[v] = u;
return true;
}
}
return false;
} struct Pessonger{
int time, sx, sy, tx, ty, dist;
bool operator < (const Pessonger &p) const{
return time < p.time;
}
};
Pessonger pess[maxn]; bool judge(int i, int j){
int t = pess[i].dist + pess[i].time + abs(pess[i].tx-pess[j].sx) + abs(pess[i].ty-pess[j].sy);
return t < pess[j].time;
} int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
for(int i = 0; i < n; ++i){
int h, s;
scanf("%d:%d %d %d %d %d", &h, &s, &pess[i].sx, &pess[i].sy, &pess[i].tx, &pess[i].ty);
pess[i].time = h * 60 + s;
pess[i].dist = abs(pess[i].sx - pess[i].tx) + abs(pess[i].sy - pess[i].ty);
}
ms(head, -1); cnt = 0;
FOR(i, 0, n) for(int j = i+1; j < n; ++j){
if(judge(i, j)) addEdge(i<<1, j<<1|1);
}
ms(match, -1);
int ans = 0;
for(int i = 0; i < (n<<1); ++i) if(match[i] < 0){
ms(used, 0); if(dfs(i)) ++ans;
}
printf("%d\n", n - ans);
}
return 0;
}

  

UVaLive 3126 Taxi Cab Scheme (最小路径覆盖)的更多相关文章

  1. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  2. UVALive3126 Taxi Cab Scheme —— 最小路径覆盖

    题目链接:https://vjudge.net/problem/UVALive-3126 题解: 最小路径覆盖:即在图中找出尽量少的路径,使得每个结点恰好只存在于一条路径上.其中单独一个点也可以是一条 ...

  3. uvalive 3126 Taxi Cab Scheme

    题意: 有m个人要坐出租车,每个人给出出发时间,出发地点和目的地(以二维坐标表示),两个地点之间所花的时间计算方式是两点之间的哈密顿距离.现在需要排遣车出去,一辆车每次只能装一个人,如果一辆车在装完一 ...

  4. hdu1350Taxi Cab Scheme (最小路径覆盖)

    Taxi Cab Scheme Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  5. Delivering Goods UVALive - 7986(最短路+最小路径覆盖)

    Delivering Goods UVALive - 7986(最短路+最小路径覆盖) 题意: 给一张n个点m条边的有向带权图,给出C个关键点,问沿着最短路径走,从0最少需要出发多少次才能能覆盖这些关 ...

  6. Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配

    /** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...

  7. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. 二分图最小路径覆盖--poj2060 Taxi Cab Scheme

    Taxi Cab Scheme 时间限制: 1 Sec  内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...

  9. UVA 1201 - Taxi Cab Scheme(二分图匹配+最小路径覆盖)

    UVA 1201 - Taxi Cab Scheme 题目链接 题意:给定一些乘客.每一个乘客须要一个出租车,有一个起始时刻,起点,终点,行走路程为曼哈顿距离,每辆出租车必须在乘客一分钟之前到达.问最 ...

随机推荐

  1. 定时器Timer&ScheduledThreadPoolExecutor

    定时器Timer&ScheduledThreadPoolExecutor /** * @ClassName: TimerTest * @author: daniel.zhao * @date: ...

  2. Java9的新特性

    2017.9.21延期了好几次的Java9正式发布,在人工智能的时代,java还能不能持续辉煌是个问题.看看java9的新特性没什么让自己想升级的意愿,因为要么时一些特性用不到,要么时已经有其它方案代 ...

  3. winform 勾选可以改变框控件

    public partial class UCCheck : UserControl { [Browsable(true), Category("修改属性"), Descripti ...

  4. Spring JUnit org.hibernate.HibernateException: Unable to get the default Bean Validation factory

    org.hibernate.HibernateException: Unable to get the default Bean Validation factory <property nam ...

  5. excel 条件格式 心的

    例1: 图1 图2 $G$16 ≠G16  用G16就可以用格式刷拖动,$G$16用格式刷刷到其它单元格保持不变,判断单元格函数 ISBLANK(G16)=TRUE

  6. laravel Hash密码 校对

    laravel加密 是使用hash不可逆的,但是可以对加密后的密码进行校对 $data = $r->all();$id = $data['id'];$user_password = bcrypt ...

  7. eclipse 的安装和汉化

    第一步:直接百度搜索eclipse,第一个就是官方网站 第二步:点击DOWNLOAD 64BIT进入下载页面 第三步:点击DOWNLOAD进行下载 If the download doesn't st ...

  8. ANSI和UNICODE编程的注意事项

    建立UNICODE编码工程 在VC60下,默认方式下建立的是ANSI编码的工程(注:编译的exe内部,其资源字符是以UNICODE保存),建立UNICODE编码工程的方法: 1.为工程添加UNICOD ...

  9. Java之MD5加密

    一.Message Digest Algorithm MD5(中文名为消息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护.该算法的文件号为RFC 1321(R.Riv ...

  10. javascript如何判断手机端的浏览器是否支持触碰功能

    if(document.hasOwnProperty("ontouchstart")) alert("浏览器支持触屏"); else alert("浏 ...