Hdu 1281

棋盘游戏

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2164    Accepted Submission(s): 1263


Problem Description
小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。 
所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也可以保证尽量多的“车”被放下。但是某些格子若不放子,就无法保证放尽量多的“车”,这样的格子被称做重要点。Gardon想让小希算出有多少个这样的重要点,你能解决这个问题么?

 

Input
输入包含多组数据, 
第一行有三个数N、M、K(1<N,M<=100 1<K<=N*M),表示了棋盘的高、宽,以及可以放“车”的格子数目。接下来的K行描述了所有格子的信息:每行两个数X和Y,表示了这个格子在棋盘中的位置。

 

Output
对输入的每组数据,按照如下格式输出: 
Board T have C important blanks for L chessmen.

 

Sample Input
3 3 4 1 2 1 3 2 1 2 2 3 3 4 1 2 1 3 2 1 3 2

 

Sample Output
Board 1 have 0 important blanks for 2 chessmen. Board 2 have 3 important blanks for 3 chessmen.
 Accepted Code:
 1 /*************************************************************************
 2     > File Name: 1281.cpp
 3     > Author: Stomach_ache
 4     > Mail: sudaweitong@gmail.com
 5     > Created Time: 2014年07月14日 星期一 20时02分46秒
 6     > Propose: 
 7  ************************************************************************/
 8 
 9 #include <cmath>
10 #include <string>
11 #include <cstdio>
12 #include <fstream>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17 
18 const int MAX_N = 100 + 5;
19 int n, m, k;
20 int cx[MAX_N], cy[MAX_N], mark[MAX_N]; 
21 int G[MAX_N][MAX_N], X[MAX_N*MAX_N], Y[MAX_N*MAX_N];
22 
23 int //通过DFS寻找增广路
24 path(int u) {
25       for (int v = 1; v <= n; v++) {
26         if (G[u][v] && !mark[v]) {
27               mark[v] = 1;
28               if (cy[v] == -1 || path(cy[v])) {
29                 cx[u] = v;
30                 cy[v] = u;
31                 return 1;
32             }
33         }
34     }
35     return 0;
36 }
37 
38 int //求解二分图的最大匹配
39 MaxMatch() {
40     memset(cx, -1, sizeof(cx));
41     memset(cy, -1, sizeof(cy));
42     int res = 0;
43     for (int i = 1; i <= n; i++) {
44         if (cx[i] == -1) {
45             memset(mark, 0, sizeof(mark));
46             res += path(i);
47         }
48     }
49     return res;
50 }
51 
52 int
53 main(void) {
54     int c = 1;
55     while (~scanf("%d %d %d", &n, &m, &k)) {
56         memset(G, 0, sizeof(G));
57         for (int i = 0; i < k; i++) {
58             scanf("%d %d", X+i, Y+i);
59             G[X[i]][Y[i]] = 1;
60         }
61         int ans = MaxMatch();
62         int cnt = 0;
63         for (int i = 0; i < k; i++) {
64             G[X[i]][Y[i]] = 0;
65             cnt += MaxMatch() < ans ? 1 : 0;
66             G[X[i]][Y[i]] = 1;
67         }
68         printf("Board %d have %d important blanks for %d chessmen.\n", c++, cnt, ans);
69     }
70 
71     return 0;
72 }

 

转载于:https://www.cnblogs.com/Stomach-ache/p/3843705.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值