UVAlive3126 Taxi Cab Scheme (minimum path overlay for dags)

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32568

Ideas

The minimum path overlay for the DAG.

Consider each person as a node, and if time is allowed to reach the edge, then the problem translates to the smallest path overlay problem on the DAG, which is to find the fewest paths so that each point is on one path.

Algorithm: Splits each node in the DAG into 2 u1,u2, and if there are edge Uvs in the DAG, The edge is u1-v2. If the maximum number of matches for this dichotomy is ans, the answer is N-ans. Think of it this way: in a path other than the tail node has a node and only one suffix node, a match as successfully found a suffix node, the maximum number of matches is the tail node minimized, that is, the number of paths minimized.

Code

1#include <cstdio>2#include <cstring>3#include <vector>4#include <iostream>5#include <algorithm>6 using namespacestd;7 8 Const intMAXN = ++Ten;9 Ten BOOLT[MAXN]; One intLKY[MAXN]; Avector<int>G[MAXN]; -  - BOOLMatchintu) { the      for(intI=0; I<g[u].size (); i++) { -         intv=G[u][i]; -         if(!T[v]) { -t[v]=1; +             if(!lky[v] | |match (Lky[v])) { -lky[v]=u; +                 return true; A             } at         } -     } -     return false; - } -  - intN; in intTSTA[MAXN],TEND[MAXN],EX[MAXN],EY[MAXN],SX[MAXN],SY[MAXN]; -  to intDistintIintj) { +     returnABS (Sx[j]-ex[i]) +abs (sy[j]-ey[i]); - } the  * intMain () { $     intK;Panax Notoginsengscanf"%d",&K); -      while(k--) { thescanf"%d",&n); +          for(intI=1; i<=n;i++) g[i].clear (); A          for(intI=1; i<=n;i++) { the             Chars[Ten]; scanf"%s", s); +Tsta[i]= ((s[0]-'0')*Ten+ (s[1]-'0'))* -+ ((s[3]-'0')*Ten+ (s[4]-'0')); -scanf"%d%d%d%d",&sx[i],&sy[i],&ex[i],&ey[i]); $tend[i]=tsta[i]+Dist (i,i); $         } -          for(intI=1; i<=n;i++) -              for(intj=1; j<=n;j++)if(i!=j) { the                 if(Tend[i]+dist (I,J) +1<=Tsta[j]) - G[i].push_back (j);Wuyi             } thememset (LKY,0,sizeof(LKY)); -         intans=0; Wu          for(intI=1; i<=n;i++) { -memset (T,0,sizeof(T)); About             if(Match (i)) ans++; $         } -printf"%d\n", N-ans); -     } -     return 0; A}

UVAlive3126 Taxi Cab Scheme (minimum path overlay for dags)

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.