[POJ3041] Asteroids (minimum point overlay-Hungarian algorithm)

Source: Internet
Author: User

Portal

Test instructions: To a n*n matrix, some lattice have obstacles, ask us to eliminate these obstacles, asked each time to eliminate a row or a column of obstacles, at least a few times. Analytical:

Take each row and each column as a point on either side of the two-part graph.

If a lattice has a barrier, it corresponds to the row and column edge.

Select the fewest points so that all edges are overwritten.

Minimum point overlay.

--code

1#include <cstdio>2#include <cstring>3 #defineM (x, a) memset (a, X, sizeof (a))4 5 using namespacestd;6 7 Const intMAXN =501;8 intN, K, CNT, ans;9 intHEAD[MAXN], NEXT[MAXN * MAXN], TO[MAXN *MAXN], BELONG[MAXN];Ten BOOLVIS[MAXN]; One  AInlinevoidAddintXinty) - { -TO[CNT] =y; theNEXT[CNT] =Head[x]; -HEAD[X] = cnt++; - } -  +InlineBOOLFindintu) - { +     intI, V; A      for(i = head[u]; I! =-1; i =Next[i]) at     { -v =To[i]; -         if(!Vis[v]) -         { -VIS[V] =1; -             if(!belong[v] | |find (Belong[v])) in             { -BELONG[V] =u; to                 return 1; +             } -         } the     } *     return 0; $ }Panax Notoginseng  - intMain () the { +     intI, x, y; Ascanf"%d%d", &n, &k); theM (-1, head); +      for(i =1; I <= K; i++) -     { $scanf"%d%d", &x, &y); $ Add (x, y); -     } -      for(i =1; I <= N; i++) the     { -M0, Vis);Wuyi         if(Find (i)) ans++; the     } -printf"%d", ans); Wu     return 0; -}
View Code

[POJ3041] Asteroids (minimum point overlay-Hungarian algorithm)

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.