标签:
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1281
题意:如题面。
这个题很巧妙,因为是车,车所在的(x,y)会使整个行和列都不能再放其他的车,所以可以根据这个规律,以行列坐标建二分图,求出最大匹配后,枚举所有可以放棋子的点,把他们归零后跑最大匹配,看看结果是否等于原先的最大匹配结果,如果相等的话,则说明这个点是关键点。
1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 using namespace std; 36 #define fr first 37 #define sc second 38 #define cl clear 39 #define BUG puts("here!!!") 40 #define W(a) while(a--) 41 #define pb(a) push_back(a) 42 #define Rint(a) scanf("%d", &a) 43 #define Rll(a) scanf("%I64d", &a) 44 #define Rs(a) scanf("%s", a) 45 #define Cin(a) cin >> a 46 #define FRead() freopen("in", "r", stdin) 47 #define FWrite() freopen("out", "w", stdout) 48 #define Rep(i, len) for(int i = 0; i < (len); i++) 49 #define For(i, a, len) for(int i = (a); i < (len); i++) 50 #define Cls(a) memset((a), 0, sizeof(a)) 51 #define Clr(a, x) memset((a), (x), sizeof(a)) 52 #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) 53 #define lrt rt << 1 54 #define rrt rt << 1 | 1 55 #define pi 3.14159265359 56 #define RT return 57 #define lowbit(x) x & (-x) 58 #define onecnt(x) __builtin_popcount(x) 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef pair<LL, LL> pll; 65 typedef map<string, int> msi; 66 typedef vector<int> vi; 67 typedef vector<LL> vl; 68 typedef vector<vl> vvl; 69 typedef vector<bool> vb; 70 71 const int maxn = 310; 72 int nu, nv; 73 int G[maxn][maxn]; 74 int linker[maxn]; 75 bool vis[maxn]; 76 77 bool dfs(int u) { 78 For(v, 1, nv+1) { 79 if(G[u][v] && !vis[v]) { 80 vis[v] = 1; 81 if(linker[v] == -1 || dfs(linker[v])) { 82 linker[v] = u; 83 return 1; 84 } 85 } 86 } 87 return 0; 88 } 89 90 int hungary() { 91 int ret = 0; 92 Clr(linker, -1); 93 For(u, 1, nu+1) { 94 Cls(vis); 95 if(dfs(u)) ret++; 96 } 97 return ret; 98 } 99 100 int n, m, k; 101 int mp[maxn][maxn]; 102 103 int main() { 104 // FRead(); 105 int u, v, _ = 1; 106 while(~scanf("%d%d%d",&n,&m,&k)) { 107 Cls(mp); Cls(G); 108 nu = n; nv = m; 109 W(k) { 110 Rint(u); Rint(v); 111 G[u][v] = 1; 112 } 113 int ret = hungary(); 114 int ans = 0; 115 For(i, 1, nu+1) { 116 For(j, 1, nv+1) { 117 if(G[i][j]) { 118 G[i][j] = 0; 119 if(ret != hungary()) ans++; 120 G[i][j] = 1; 121 } 122 } 123 } 124 printf("Board %d have %d important blanks for %d chessmen.\n", _++, ans, ret); 125 } 126 RT 0; 127 }
标签:
原文地址:http://www.cnblogs.com/vincentX/p/5803994.html