HDU 1281 Board Game

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1281

Board games

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 3096 Accepted Submission (s): 1827

Problem description and Gardon play a game: to a n*m chess board, in the lattice to put as much as possible some chess inside the "car", and so they can not attack each other, which is of course very simple, but Gardon limited only some 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 inputs contain multiple sets of data,The first line has three numbers N, M, K (1<n,m<=100 1<k<=n*m), indicating the height and width of the board, and the number of squares that can be put "cars". The next K-line describes all the lattice information: two x and y per line, indicating the position of the lattice in the checkerboard.

Output for each set of data entered, as shown in the following format:Board T has C important blanks for L chessmen.

Sample INPUT3 3 41 21 32 12 23 3 41 21 32 13 2

Sample Outputboard 1 has 0 important blanks for 2 chessmen. Board 2 has 3 important blanks for 3 chessmen.

Topic Analysis:

1. To put as many cars as possible, it is to find the maximum match

Put the horizontal axis into the x set, the ordinate in the Y set to form a two-dimensional graph coordinates (x, y) location of the car,

There is a connection between x and Y, and the car cannot attack each other so there is no public endpoint between the two lines.

Which translates to the maximum match

2. The number of important points to ask

The given can put the car's point one delete, then the maximum match, if the maximum match is less than the maximum match before the deletion

Then this point is an important point.

#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#defineN 110using namespacestd;intG[n][n], vis[n], used[n];intN, M, K;structst{intA, B;} Node[n*N];BOOLFind (intu) {    inti;  for(i =1; I <= m; i++)    {        if(!vis[i] &&G[u][i]) {Vis[i]=1; if(!used[i] | |Find (Used[i])) {Used[i]=u; return true; }        }    }    return false;}intsolve () {intnum =0, I; memset (Used,0,sizeof(used));  for(i =1; I <= N; i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) Num++; }    returnnum;}intMain () {intI, p =0;  while(~SCANF ("%d%d%d", &n, &m, &k)) {p++; memset (G,0,sizeof(G));  for(i =1; I <= K; i++) {scanf ("%d%d", &AMP;NODE[I].A, &node[i].b); G[NODE[I].A][NODE[I].B]=1; }        intAns =solve (); intt =0;  for(i =1; I <= K; i++) {g[node[i].a][node[i].b]=0; if(Ans >solve ()) T++; G[NODE[I].A][NODE[I].B]=1; } printf ("Board%d has%d important blanks for%d chessmen.\n", p, t, ans); }    return 0;}
View Code

HDU 1281 Board Game

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.