UVALive 3415 Guardian of Decency(最大独立集)
2016-05-14 03:31
387 查看
题目链接:
UVALive 3415 Guardian of Decency
题意:
刘汝佳的大白书P356页上的题目.
最大独立集.
UVALive 3415 Guardian of Decency
题意:
刘汝佳的大白书P356页上的题目.
最大独立集.
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <climits> #include <cmath> #include <ctime> #include <cassert> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; typedef long long ll; const int MAX_N = 510; int T, n, m, K, total; int head[MAX_N * MAX_N], vis[MAX_N], match[MAX_N]; struct Student{ int height; string sex, music, game; }boy[MAX_N], girl[MAX_N]; struct Edge{ int to,next; }edge[MAX_N * MAX_N]; inline bool check(int i, int j) { if(abs(boy[i].height - girl[j].height) > 40) return true; if(boy[i].music != girl[j].music) return true; if(boy[i].game == girl[j].game) return true; return false; } inline void AddEdge(int from, int to) { edge[total].to = to; edge[total].next = head[from]; head[from] = total++; } inline bool dfs(int u) { for(int i = head[u]; i != -1; i = edge[i].next){ int to = edge[i].to; if(vis[to]) continue; vis[to] = 1; if(match[to] == -1 || dfs(match[to])){ match[to] = u; return true; } } return false; } inline int Hungary() { int res = 0; memset(match, -1, sizeof(match)); for(int i = 0; i < n; i++){ memset(vis, 0, sizeof(vis)); if(dfs(i)) res++; } return res; } int main() { IOS; cin >> T; while(T--){ cin >> K; n = m = 0; for(int i = 0; i < K; i++){ int h; string tmp1, tmp2, tmp3; cin >> h >> tmp1 >> tmp2 >> tmp3; if(tmp1[0] == 'M') { boy .height = h, boy .music = tmp2; boy .game = tmp3, n++; }else { girl[m].height = h, girl[m].music = tmp2; girl[m].game = tmp3, m++; } } total = 0; memset(head, -1, sizeof(head)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(check(i, j) == false ) AddEdge(i, j); } } int ans = Hungary(); cout << K - ans << endl; } return 0; }
相关文章推荐
- UVALive 11419 SAM I AM (最小点覆盖输出)
- UVALive 11383 - Golden Tiger Claw(最小权匹配)
- 项目构建maven——maven的安装
- mininet实战2
- Floodlight安装指南
- 人像摄影技巧——镜头差异可改变脸部印象
- HDU 4619 Warm up 2(最大独立集)
- XML系列:(7)XML解析-Dom4j的DOM解析方式更新XML
- 爬虫闯关之旅-2
- 【JAVA】二 JAVA reference
- XML系列:(6)XML解析-Dom4j的DOM解析方式读取XML
- 7的倍数和末尾含7的数
- Best Practice: SharedPreferences
- 全局变量的特殊作用
- MATLAB和VS混合编程
- Codeforces Round #352 (Div. 2) (A-E)
- Java Socket多个客户端与服务器通信
- 完美乘积
- vector的使用
- Win7 Qt4.8.5+QtCreator2.8.0+mingw配置过程