POJ 3686 The windy ' s "min right match (Shen Jiantu AH)"

Source: Internet
Author: User

The main idea: there are n tasks m machines that tell you n*m matrix represents the time each task takes to complete on each machine

Do all tasks have the fewest total time to complete? (for example, the first task completes the second task in the first minute, the total time is 1 + 2 = 3 When the two minute is completed)

Analysis:

There is no train of thought when you do the problem.

Later on the Internet search, feel the map is very powerful

Assuming the optimal situation, the time required for each task is A1, A2, A3, ..., an

So total time t = n * A1 + (n-1) * A2 + ... + 2 * an-1 + an

Which means you just have to consider the coefficients.

Let's just assume that there's only one machine.

So that means choosing a different factor for each task's time.

That is, from each task to the machine to build N-side, respectively, the coefficient edge weight value of k*cost can be

Expansion to M machine as long as each machine to be split into n points on it ~ ~

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5 using namespacestd;6 7 Const intMAXN = -;8 Const intINF =1000000000;9 Ten intSX[MAXN], SY[MAXN *MAXN]; One intLX[MAXN], LY[MAXN *MAXN]; A intLINK[MAXN *MAXN]; - intLIX[MAXN]; - intW[MAXN][MAXN *MAXN]; the intN, M; -  - BOOLFind (inti) { -Sx[i] =true; +      for(intj =1; J <= M; J + +) { -         if(! SY[J] && Lx[i] + ly[j] = =W[i][j]) { +SY[J] =true; A             if(Link[j] = =0||Find (Link[j])) { atLix[i] =J; -LINK[J] =i; -                 return true; -             } -         } -     } in     return false; - } to  + intKM () { -      for(inti =1; I <= N; i++) { theLx[i] =-INF; *          for(intj =1; J <= M; J + +) { $Lx[i] =Max (Lx[i], w[i][j]);Panax Notoginseng         } -     } thememset (Ly,0,sizeof(Ly)); +memset (Link,0,sizeof(Link)); A      for(intv =1; V <= N; v++) { thememset (Sx,0,sizeof(Sx)); +memset (Sy,0,sizeof(Sy)); -          while(1) { $             if(Find (v)) Break; $             intDMin =INF; -              for(inti =1; I <= N; i++) { -                 if(Sx[i]) { the                      for(intj =1; J <= M; J + +) { -                         if(! SY[J] && Lx[i] + ly[j]-W[I][J] <DMin) {WuyiDMin = Lx[i] + ly[j]-W[i][j]; the                         } -                     } Wu                 } -             } About              for(inti =1; I <= N; i++) { $                 if(Sx[i]) { -Lx[i]-=DMin; -Sx[i] =0; -                 } A             } +              for(inti =1; I <= m; i++) { the                 if(Sy[i]) { -Ly[i] + =DMin; $Sy[i] =0; the                 } the             } the         } the     } -     intsum =0; in      for(inti =1; I <= N; i++) { theSum + =W[i][lix[i]]; the     } About     returnsum; the } the  the intMAT[MAXN][MAXN]; + intMain () { -     intT; thescanf"%d",&t);Bayi      while(t--) { thescanf"%d%d", &n, &m); the          for(inti =1; I <= N; i++) { -              for(intj =1; J <= M; J + +) { -scanf"%d",&mat[i][j]); the             } the         } the          for(intK =1; K <= N; k++) { the              for(inti =1; I <= m; i++) { -                  for(intj =1; J <= N; J + +) { thew[k][(I-1) * n + j] =-mat[k][i] *J; the                 } the             }94         } them = n *m; the         intANS1 =-KM (); the         DoubleAns = ans1 *1.0/N;98printf"%.6f\n", ans); About     } -     return 0;101}
View Code

POJ 3686 The windy ' s "min right match (Shen Jiantu AH)"

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.