First of all, say test instructions, Q-area, M-task, each area of the task may have multiple, and then give you a time to go around the matrix, each task has a start and duration, ask the minimum number of workers required? Each worker can only perform one task at a time.
By test instructions, my immediate reaction was to take the point apart, because each area might have multiple tasks, so each task is treated as a little bit, and then one thing needs to be considered, whether a worker should go to a place that is closest to him and has a mission right after the Qi region is finished QJ So is he supposed to take the nearest route from Qi to QJ? The next step is out, find the shortest distance between all areas, with a key Floyd. Then you can build the map (the direction), the task can be connected together, according to the start time of the previous task + Duration + to the next point of time <= next point of the start time to connect the edge (do not change the area to the next point of time is 0), then the problem becomes how many workers can take the picture finished? That is, the minimum path coverage, the direct Hungarian algorithm to fix.
Okay, on the code.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <vector>5 #defineMAXN 5006 #defineINF 0XFFFFFFF7 using namespacestd;8 9 structEdgeTen { One intPos,realpos,start,need; A }RELA[MAXN]; -vector<int>Q[MAXN]; - intMIZE[MAXN][MAXN],POINT[MAXN]; the intVIS[MAXN],LINK[MAXN]; - intn,m,sum; - voidInit () - { + for(intI=0; i<=maxn;i++) - q[i].clear (); +memset (RelA,0,sizeof(RelA)); Amemset (Mize,0,sizeof(Mize)); atmemset (Point,0,sizeof(point)); - for(intA=1; a<=n;a++) - for(intb=1; b<=n;b++) - { -scanf"%d",&mize[a][b]); - if(mize[a][b]==-1) mize[a][b]=inf; in } - to for(intC=1; c<=m;c++) + { -scanf" %d%d%d",&rela[c].pos,&rela[c].start,&rela[c].need); the intp=0; * for(intD=1;d <c;d++) $ {Panax Notoginseng if(Rela[d].pos==rela[c].pos) p++; - } therela[c].realpos=rela[c].pos+n*p; +point[rela[c].realpos]=1; A if(Sum<rela[c].realpos) sum=Rela[c].realpos; the } + } - voidFloyd () $ { $ for(intI=1; i<=n;i++) - { - for(intj=1; j<=n;j++) the { - for(intk=1; k<=n;k++)Wuyi { themize[j][k]=mize[j][k]<mize[i][k]+mize[j][i]?mize[j][k]:mize[i][k]+Mize[j][i]; - } Wu } - } About $ - } - voidSet_map () - { A for(intI=1; i<=m;i++) + { the intRealpos=rela[i].realpos,pos=rela[i].pos,time=rela[i].need+Rela[i].start; - for(intj=1; j<=m;j++) $ { the if(j==i)Continue; the inta=rela[j].realpos,b=rela[j].pos,t=Rela[j].start; the //if (mize[pos][b]==-1| | MIZE[B][POS]==-1) continue; the if(time+mize[pos][b]<=t)//It doesn't matter how the matrix symmetry is written. - { in Q[realpos].push_back (a); the //Q[a].push_back (realpos); the } About } the } the /*for (int i=1;i<=8;i++) the { + if (q[i].size () ==0) continue; - cout<<i<< ":" <<endl; the for (int j=0;j<q[i].size (); j + +)Bayi { the cout<<q[i][j]<< ""; the } - cout<<endl; - }*/ the } the intDfsintx) the { the for(intI=0; I<q[x].size (); i++) - { the inty=Q[x][i]; the if(!Vis[y]) the {94Vis[y] =true; the if(link[y]==-1||DFS (Link[y])) the { theLink[y] =x;98 return true; About } - }101 }102 return false;103 }104 voidSolve () the {106 ints=0;107memset (link,-1,sizeof(link));108 for(intI=1; i<=sum;i++)109 { the if(point[i]==0)Continue;111memset (Vis,0,sizeof(Vis)); the if(Dfs (i)) s++;113 } theprintf"%d\n", M-s); the } the intMain ()117 {118 while(SCANF ("%d%d", &n,&m)! =EOF)119 { - if(n==0&&m==0) Break;121sum=0;122 init ();123 Floyd ();124 Set_map (); the solve ();126 }127 return 0; -}View Code
POJ3216 Minimum Path Overlay