Problem F

最小边覆盖

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <algorithm>
//#include "myAlgorithm.h"

#define MAX 10005
#define OFFENCE (1e9 + 5)
#define INF (1e8 + 5)
#define eps 1e-9
#define Rep(s, e) for( int i = s; i <= e; i++)
#define Cep(e, s) for( int j = e; j >= s; j --)
#define PI acos(-1.0)
//#pragma comment(linker, "/STACK:36777216") ///传说中的外挂
using namespace std;
int n;
int match[MAX];
bool v[MAX];
vector<vector<int> >adj;
void init() {
    memset(match, -1, sizeof(match));
    adj.assign(n + 2, vector<int>() );
}
bool find(int node) {
    int len = adj[node].size(), pos;
    Rep(0 , len - 1) {
        pos = adj[node][i];
        if(!v[pos]) {
            v[pos] = 1;
            int pre = match[pos];
            if(pre == -1 || find(pre)) {
                match[pos] = node;
                return true;
            }
        }
    }//cout<<endl;
    return false;
}


struct Ride {
    int hh, mm;
    int sa, sb, ea, eb;
} r[MAX];

void make_adj() {
    Rep(0, n -1) {
        for(int j = i + 1; j < n; j++) {
            int rt = abs(r[i].ea - r[j].sa) + abs(r[i].eb - r[j].sb);
            int mt = (r[j].hh - r[i].hh) * 60 + r[j].mm - r[i].mm  -  rt - (abs(r[i].ea - r[i].sa) + abs(r[i].eb - r[i].sb));
            if(mt > 0) {
                adj[i].push_back(j);
                //  adj[j].push_back(i);
            }
        }
    }
}
int main() {

    int T;
    cin>>T;
    while(T--) {
        cin>>n;
        init();
        Rep(0, n - 1) {
            scanf(" %d:%d %d %d %d %d", &r[i].hh, &r[i].mm, &r[i].sa, &r[i].sb,&r[i].ea, &r[i].eb);
            //cin>>r[i].hh>>tt>>r[i].mm>>r[i].sa>>r[i].sb>>r[i].ea>>r[i].eb;
            //cout<<r[i].sa<<" "<<r[i].sb<<" "<<r[i].ea<<r[i].eb<<endl;

        }
        make_adj();
        int fc = 0;
        Rep(0, n -1) {
            if(find(i))fc++;
            memset(v, 0, sizeof(v));
        }
        cout<<n - fc<<endl;
    }

    return 0;
}
/**

*/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值