HDU 1281 board game (two-part chart matching)

Source: Internet
Author: User

HDU 1281 Board Game

Description
Xiaoxi and Gardon are playing a game: on a n*m board, in the grid to put as much as possible in some chess inside the "car", and so they can not attack each other, which is of course very simple, but Gardon limited only certain lattice can be put, Xiaoxi is still easy to solve the problem (see) Note that the location of the car does not affect the car's mutual attack.
So now Gardon want to let Xiao-Xi to solve a more difficult problem, in order to ensure as much as possible "car" premise, some of the board can be avoided, that is, not on these squares to put the car, but also to ensure that as much as possible "car" was put down. However, if some lattice does not put the son, there is no guarantee to put as much as possible "car", such a lattice is called to do important points. Gardon want to figure out how many of these important points, can you solve this problem?

Input
Input contains multiple sets of data,
The first line has three numbers n, M, K (1

Title: Chinese question. Problem-Solving ideas: Row on the left, listed on the right, according to can put "car" coordinates, to the ranks of the building side. The map is built with the Hungarian algorithm to find the maximum match. Then traverse all the edges, delete one and then the maximum match, if the result is different from the previous one, then the point is the "important point", please remember to restore the edge.
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>#include <queue>using namespace STD;typedef Long LongllConst intN = the;Const intM =10000;Const intINF =0x3f3f3f3f;intN, M, K, case, ans;intX[M], y[m], vis[n];intG[n][n], r[n];voidInput () {memsetG0,sizeof(G));memsetR0,sizeof(R)); for(inti =0; I < K; i++) {scanf("%d%d", &x[i], &y[i]); G[x[i]][y[i]] =1; }}intFindintx) { for(inti =1; I <= m; i++) {if(G[x][i] &&!vis[i]) {Vis[i] =1;if(R[i] = =0|| Find (R[i])) {r[i] = x;return 1; }         }       }return 0;}intHungary () {intAns =0; for(inti =1; I <= N; i++) {memset(Vis,0,sizeof(VIS));if(Find (i)) ans++; }returnAns;}voidSolve () {intAns = Hungary ();intCNT =0; for(inti =0; I < K; i++) {memsetR0,sizeof(R)); G[x[i]][y[i]] =0;intres = Hungary ();if(Res < ans) cnt++; G[x[i]][y[i]] =1; }printf("Board%d has%d important blanks for%d chessmen.\n", case++, CNT, ans);}intMain () {case =1; while(scanf(" %d%d%d", &n, &m, &k) = =3) {input ();    Solve (); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without BO Master permission cannot reprint.

HDU 1281 board game (two-part chart matching)

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.