POJ 3216 Repairing Company

Source: Internet
Author: User

Topic Link http://poj.org/problem?id=3216

Topic explanation

Test instructions: Lily is a maintenance company that serves the city's Q block. One day, the company received the M repair task, wherein the i occurred in the PI block, on the arrival of any repairman to the last deadline Ti, is it's start time and needs a repairman Di time to complete. The repairman finishes the current single task and must move (moving to the next block takes time) to the next task to complete the next one. With a map in hand, Lily wants to know the least of the repairman to be able to complete all the tasks of gold today.

Input: First input two number q, M, represents a Q block, M task, the following input QXQ number, that is, a matrix, Qij represents the first block to the J block of Time, if 1, it means there is no road between them;

Next is M-line, 3 numbers per line, pi, Ti,di

Least-output repairman

Thinking analysis

Analysis: First, according to the map to find the shortest path between any two blocks, then according to the task, to find the maximum matching of the two-dimensional graph, the smallest path coverage can be obtained;

How to build a binary diagram: if Di + Qij <= Tj, that is, the current task end time plus the path time is not greater than the next task start time, the build edge

Code:

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <cctype>5#include <cmath>6#include <algorithm>7#include <vector>8#include <queue>9#include <stack>Ten#include <map> One  A using namespacestd; -  - Const intinf=0x3f3f3f3f; the #defineMAXN 300 - intEDGE[MAXN][MAXN], q, m; - BOOLVISIT[MAXN], G[MAXN][MAXN]; - intMATCH[MAXN]; + structTask - { +     intID, S, e; A }TASK[MAXN]; at voidFloyd () - { -      for(inti =1; I <= Q; i++) -     { -          for(intj =1; J <= Q; J + +) -         { in              for(intK =1; K <= Q; k++) -             { to                 if(Edge[j][i] + edge[i][k] <Edge[j][k]) +EDGE[J][K] = Edge[j][i] +Edge[i][k]; -             } the         } *     } $ }Panax Notoginseng  - BOOLDfsintnum) the { +     intU = task[num].id, T1 = task[num].s, D1 =task[num].e; A      for(inti =0; I < m; i++) the     { +         intv = task[i].id, t2 = task[i].s, d2 =task[i].e; -         //printf ("edge =%d m =%d D1 =%d t2 =%d\n", Edge[u][v], M, D1, T2); $         if(Edge[u][v]!=inf &&!visit[i] && t1+d1+edge[u][v]<=T2) $         { -             //puts ("hehe"); -Visit[i] =true; the             if(Match[i] = =-1||DFS (Match[i])) -             {WuyiMatch[i] =num; the                 return true; -             } Wu         } -     } About     return false; $ } - intHungary () - { -     intAns =0; Amemset (Match,-1,sizeof(Match)); +      for(inti =0; I < m; i++) the     { -memset (Visit,false,sizeof(visit)); $         if(Dfs (i)) theans++; the         //printf ("ans =%d", ans); the     } the     returnans; - } in intMain () the { the     intP, D, t; About      while(SCANF ("%d%d", &q, &m) && q+m) the     { the          for(inti =1; I <= Q; i++) the         { +              for(intj =1; J <= Q; J + +) -             { thescanf"%d", &edge[i][j]);Bayi                 if(Edge[i][j] = =-1) theEDGE[I][J] =INF; the             } -         } - Floyd (); the          for(inti =0; I < m; i++) the         { thescanf" %d%d%d", &p, &t, &d); theTask[i].id = p; Task[i].s = t; TASK[I].E =D; -         } theprintf"%d\n", M-Hungary ()); the}
View Code

POJ 3216 Repairing Company

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.