POJ 2060 Taxi Cab Scheme(匈牙利—最小路徑覆蓋)
如果一個計程車在接完一個客人之後還可以接另一位客人,那這兩點之間連一條邊。
現在突然有個疑問,為什麼不用求Floyd?好吧,我明白了,建圖過程中就把所有邊都連上了,相當於求了一遍Floyd~
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const int MAX_N = 500 + 10; struct Node { int t1, t2, x1, y1, x2, y2; }; struct Edge { int v, next; }; Edge e[MAX_N * (MAX_N - 1)]; Node node[MAX_N]; bool vis[MAX_N]; int head[MAX_N], link[MAX_N]; int n, cnt; void addEdge(int u, int v) { e[cnt].v = v; e[cnt].next = head[u]; head[u] = cnt++; } bool DFS(int u) { int v; for(int i = head[u]; i != -1; i = e[i].next) { v = e[i].v; if(!vis[v]) { vis[v] = 1; if(link[v] == -1 || DFS(link[v])) { link[v] = u; return true; } } } return false; } int MaxMatch() { int ans = 0; memset(link, -1, sizeof(link)); for(int i = 0; i < n; i++) { memset(vis, 0, sizeof(vis)); if(DFS(i)) ans++; } return ans; } int dis(int x1, int y1, int x2, int y2) { return abs(x2 - x1) + abs(y2 - y1); } int main() { int T; scanf("%d", &T); while(T--) { cnt = 0; memset(head, -1, sizeof(head)); scanf("%d", &n); int h, m; for(int i = 0; i < n; i++) { scanf("%d:%d%d%d%d%d", &h, &m, &node[i].x1, &node[i].y1, &node[i].x2, &node[i].y2); node[i].t1 = h * 60 + m; node[i].t2 = node[i].t1 + dis(node[i].x1, node[i].y1, node[i].x2, node[i].y2); } for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(node[i].t2 + dis(node[i].x2, node[i].y2, node[j].x1, node[j].y1) + 1 <= node[j].t1) addEdge(i, j); printf("%d\n", n - MaxMatch()); } return 0; }
相關推薦
POJ 2060 Taxi Cab Scheme(匈牙利—最小路徑覆蓋)
如果一個計程車在接完一個客人之後還可以接另一位客人,那這兩點之間連一條邊。 現在突然有個疑問,為什麼不用求Floyd?好吧,我明白了,建圖過程中就把所有邊都連上了,相當於求了一遍Floyd~ #include <iostream> #include <
POJ 2060 Taxi Cab Scheme(最小路徑覆蓋)
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>
poj2060——Taxi Cab Scheme(最小路徑覆蓋)
起點 schedule n) def simple ted des single output Description Running a taxi station is not all that simple. Apart from the obvious demand
POJ_2060_Taxi Cab Scheme【最小路徑覆蓋】
/* Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6460 Accepted: 2720 Description Running a taxi station is not a
Poj-2060 Taxi Cab Scheme 二分圖最小路徑覆蓋
題目連結 計程車公司有n個預約, 每個預約有時間和地點, 地點分佈在二維整數座標系上, 地點之間的行駛時間為兩點間的曼哈頓距離(|x1 - x2| + |y1 - y2|)。一輛車可以在運完一個乘客後運另一個乘客, 條件是此車要在預約開始前一分鐘之前到達出發地, 問最少需要
poj 3020 Antenna Placement (二分圖最小路徑覆蓋)
#include<stdio.h> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #includ
POJ2060 Taxi Cab Scheme【二分圖最小路徑覆蓋】
題目連結: 題目大意: 計程車公司每天有有N項預約,每項預約有開始時間(xx:xx),出發地點(a,b)與目的地點(c,d)。 完成這項預約行駛需要的時間是|a-c| + |b-d|分鐘。一輛車可
Antenna Placement POJ - 3020 二分圖匹配 匈牙利 拆點建圖 最小路徑覆蓋
題意:圖沒什麼用 給出一個地圖 地圖上有 點 一次可以覆蓋2個連續 的點( 左右 或者 上下表示連續)問最少幾條邊可以使得每個點都被覆蓋 最小路徑覆蓋 最小路徑覆蓋=|G|-最大匹配數 &
Antenna Placement POJ - 3020 二分圖匹配 匈牙利 拆點建圖 最小路徑覆蓋
har 一個 article main 左右 int 集合 || sin 題意:圖沒什麽用 給出一個地圖 地圖上有 點 一次可以覆蓋2個連續 的點( 左右 或者 上下表示連續)問最少幾條邊可以使得每個點都被覆蓋 最小路徑覆蓋 最小路徑覆蓋=|G|-最大匹配數
UVALive 3126 Taxi Cab Scheme(最大匹配問題)
Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coordi- nation of the cabs in order to pick up the
周賽 POJ 2060 最小路徑覆蓋
題意:給你N個乘客的時間,每個時間出租車必須從(a,b)到(c,d) 。 問最少需要多少出租車可以滿足所有乘客的需求。 建圖:任意兩個乘客,算出時間差,比較從乘客1的起點到乘客2的起點的時間,如果能到,那麼相連。 就是求最小路徑覆蓋。 #include <iostr
POJ 2060 最小路徑覆蓋
題目: Taxi Cab Scheme Time Limit: 1000MSMemory Limit: 30000K Total Submissions: 4432Accepted: 1868 Description Running a taxi station is no
POJ 2060 最小路徑覆蓋 二分圖
這題是一道簡單的最小路徑覆蓋題目,最小路徑覆蓋的數目等於點的數目減去最大匹配數。#include <stdio.h> #include <string.h> #include <iostream> #include <algor
POJ 2060 (最小路徑覆蓋)
題意:在二維的平面中,給出一些任務,每個任務要求在指定的時間,必須有一輛taxi從起點出發,並最終到達終點,由於可能產生時間衝突(具體參詳題目),所以可能需要多輛taxi,問需要最少的taxi數量是多少。 構圖:可以將每個任務看成一個點,如果兩個任務的時間沒
POJ - 2376 Cleaning Shifts 貪心(最小區間覆蓋)
red his 時間 sin lines farmer cte number limit Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do
POJ - 1325 Machine Schedule 二分圖 最小點覆蓋
code mach 切換 才幹 ces 任務 ack div con 題目大意:有兩個機器,A機器有n種工作模式,B機器有m種工作模式,剛開始兩個機器都是0模式。假設要切換模式的話,機器就必須的重新啟動 有k個任務,每一個任務都能夠交給A機器的i模式或
POJ 3041 Asteroids (二分圖最小點覆蓋集)
0ms ext ted with width any print scrip avi Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24789
POJ 3216 Repairing Company(最小路徑覆蓋)
false 時間 cpp algorithm true 持續時間 set rgb AR POJ 3216 Repairing Company id=3216">
poj 2594 Treasure Exploration (floyd傳遞閉包+最小路徑覆蓋) (bitset優化floyd)
這道題為有向圖有相交邊的情況。。不能直接求最大匹配 先用floyd處理一下邊 // // main.cpp // wzazzy // // Created by apple on 2018/10/23. // Copyright © 2018年 apple. All rights r
poj 2594 Treasure Exploration (floyd傳遞閉包+最小路徑覆蓋)
這道題為有向圖有相交邊的情況。。不能直接求最大匹配 先用floyd處理一下邊 // // main.cpp // wzazzy // // Created by apple on 2018/10/23. // Copyright © 2018年 apple. Al