zoukankan      html  css  js  c++  java
  • POJ 2060 Taxi Cab Scheme【最小路径覆盖】

    T - Taxi Cab Scheme
    Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u
    Appoint description: 

    Description

    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 - 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

    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.

    Output

    For each scenario, output one line containing the minimum number of cabs required to carry out all the booked taxi rides.

    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

    今天我又把题目粘过来了, 原因很简单, 我又读错题了 TAT

    大意:有n个点,给你一个起始时间,从一个点到另一个点需要的时间是横纵坐标差的绝对值之和, 问需要派出多少cab
    分析:最小路径覆盖 = n - 最大匹配

    代码:
     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <vector>
     5 #include <cmath>
     6 using namespace std;
     7 
     8 const int maxn = 505;
     9 const int INF = 1000000000;
    10 
    11 int n;
    12 int vis[maxn];
    13 int Link[maxn];
    14 vector<int> G[maxn];
    15 bool Find(int u) {
    16     for(int i = 0; i < G[u].size(); i++) {
    17         int v = G[u][i];
    18         if(!vis[v]) {
    19             vis[v] = 1;
    20             if(Link[v] == - 1 || Find(Link[v])) {
    21                 Link[v] = u;
    22                 return true;
    23             }
    24         }
    25     }
    26     return false;
    27 }
    28 
    29 int solve() {
    30     int cnt = 0;
    31     memset(Link, -1, sizeof(Link));
    32     for(int i = 1; i <= n; i++) {
    33         if(G[i].size()) {
    34             memset(vis, 0, sizeof(vis));
    35             if(Find(i)) cnt++;
    36         }
    37     }
    38     return cnt;
    39 }
    40 
    41 int a[maxn], b[maxn], c[maxn], d[maxn], t[maxn];
    42 bool check(int i, int j) {
    43     if(t[j] - ((fabs(c[i] - a[i]) + fabs(d[i] - b[i]) + t[i]) + fabs(a[j] - c[i]) + fabs(b[j] - d[i])) >= 1) {
    44         return true;
    45     }
    46     return false;
    47 }
    48 
    49 int main() {
    50     int tt;
    51     int x, y;
    52     scanf("%d",&tt);
    53     while(tt--) {
    54         scanf("%d",&n);
    55         for(int i = 1; i <= n; i++) {
    56             G[i].clear();
    57             scanf("%d:%d",&x,&y);
    58             t[i] = x * 60 + y;
    59             scanf("%d %d %d %d",&a[i], &b[i], &c[i], &d[i]);
    60         }
    61         for(int i = 1; i <= n; i++) {
    62             for(int j = 1; j <= n; j++) {
    63                 if(i == j) continue;
    64                 if(check(i, j)) {
    65                     G[i].push_back(j);
    66                 }
    67             }
    68         }
    69         printf("%d
    ", n - solve());
    70     }
    71     return 0;
    72 }
    View Code
  • 相关阅读:
    css最简单的在背景图片上显示模糊背景色的方法
    css添加网格背景
    获取bing必应图片
    JavaScript超过一定高度导航添加类名
    6行css就可以解决的瀑布流布局的方法
    css实现背景图横向滚动
    JavaScript根据一个元素的显示隐藏控制另一个元素的显示和隐藏
    JavaScript判断地址栏链接与导航栏链接是否一致并给导航添加class
    JavaScript实现选中文字自动复制
    Day 74 算法基础(二)
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3942700.html
Copyright © 2011-2022 走看看