POJ2060 Taxi Cab Scheme

注意一辆太可惜是从一个起点到达终点再从这个终点抵达下一个位置的起点,最小路径覆盖


#include <iostream>
#include <string.h>
using namespace std;
const int size = 600;
struct node
{
       int time;
       int sx, sy, ex, ey;       
}mapp[size];

bool maze[size][size];
int match[size];
bool visited[size];
bool dfs(int x, int n)
{
     for (int i = 1; i <= n; i ++){
         if (!maze[x][i] || visited[i])continue;
         visited[i] = true;
         if (match[i] == -1 || dfs(match[i], n)){
            match[i] = x;
            return true;             
         }
     }     
     return false;
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t --){
          int n;
          scanf("%d", &n);
          for (int i = 1; i <= n; i ++){
              int hh, mm, sx,sy,ex,ey;
              scanf("%d:%d %d %d %d %d", &hh, &mm, &mapp[i].sx, &mapp[i].sy, &mapp[i].ex,&mapp[i].ey);
              mapp[i].time = hh*60+mm;    
          }
          memset(maze, false, sizeof(maze)); 
          for (int i = 1; i <= n; i ++){
              int k = mapp[i].time + abs(mapp[i].sx-mapp[i].ex) + abs(mapp[i].sy-mapp[i].ey)+1;
              for (int j = 1; j <= n; j ++){
                  if (i==j)continue;
                  if (mapp[j].time>= k+abs(mapp[i].ex-mapp[j].sx) + abs(mapp[i].ey-mapp[j].sy)){
                     maze[i][j] = true;                   
                  }    
              }    
          }
          memset(match, -1, sizeof(match));
          int ans = 0;
          for (int i = 1; i <= n; i ++){
              memset(visited, false, sizeof(visited));
              if (dfs(i, n))ans ++;    
          }
          printf("%d\n", n-ans);
    }   
    return 0;    
}


你可能感兴趣的:(struct,Scheme)