Title Link: 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): 2905 Accepted Submission (s): 1702
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. Authorgardon Source Hangzhou Electric ACM Training Team Training Tournament (VI) The main idea is that there can be no attack between the car and the car. There is also a part of the position where you cannot place a pawn. Problem-solving ideas: A row can only be one column, then for the horizontal ordinate x and y a row of only one intersection. So we can convert these points to a two-point chart based on the x-coordinate and the y-coordinate. For the important point, we can take this point off, blacked out and let him go, and then in a two-point match, if the maximum match value is found to be small, then this is the important point. See the code.
1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intvis[ the],map[ the][ the],n,m;8 intok[ the];9 Ten BOOLFind (intx) One { A for(intI=1; i<=n; i++) - { - if(map[x][i]==1&&!Vis[i]) the { -vis[i]=1; - if(!Ok[i]) - { +ok[i]=x; - return true; + } A Else at { - if(Find (ok[i]) = =true) - { -ok[i]=x; - return true; - } in } - } to } + return false; - } the * intMain () $ {Panax Notoginseng intk,x,y,ans,flag=1; - while(~SCANF ("%d%d%d",&n,&m,&k)) the { +ans=0; Amemset (Map,0,sizeof(MAP)); the /*for (int i=1;i<=n;i++) + { - for (int j=1;j<=m;j++) $ { $ map[i][j]=1; - } - }*/ theMemset (OK,0,sizeof(OK)); - while(k--)Wuyi { thescanf"%d%d",&x,&y); -map[x][y]=1; Wu } - for(intI=1; i<=m; i++) About { $memset (Vis,0,sizeof(Vis)); - if(Find (i) = =true) - { -ans++; A } + } the intsum=0; - for(intI=1; i<=n; i++) $ { the for(intj=1; j<=m; J + +) the { the if(map[i][j]==1) the { -Memset (OK,0,sizeof(OK)); in intkk=0; themap[i][j]=0; the for(intk=1; k<=m; k++) About { thememset (Vis,0,sizeof(Vis)); the if(Find (k) = =true) the { +kk++; - } the }Bayi if(kk<ans) thesum++; themap[i][j]=1; - } - } the } theprintf ("Board%d has%d important blanks for%d chessmen.\n", flag++, Sum,ans); the } the return 0; -}
HDU 1281 board game (binary match)