HDU 1498 50 years, 50 colors(最小顶点覆盖)
来源:互联网 发布:网络爬虫 java 开源 编辑:程序博客网 时间:2024/05/28 11:47
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1498
思路:和HDU2119有点像,枚举每种颜色的气球就行
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long ll;const int maxn = 40000;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int map1[110][110];int map2[110][110];int parter[110];int visit[110];int n;int find1(int x){ for (int i = 1; i <= n; i++) { if (map2[x][i] && visit[i] == 0)//如果有边 且 未被搜索过 { visit[i] = 1; if (parter[i] == 0 || find1(parter[i]))//如果该男孩没有搭档或者能够给该男孩另找到一搭档 { parter[i] = x; return 1; } } } return 0;}int solve(int x){ memset(map2, 0, sizeof(map2)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (map1[i][j] == x) map2[i][j] = 1; } } int sum = 0; memset(parter, 0, sizeof(parter)); for (int i = 1; i <= n; i++) { memset(visit, 0, sizeof(visit)); if (find1(i)) sum++; } return sum;}int main(){ int k; int b[110]; while (scanf("%d%d", &n, &k) ,n+k) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &map1[i][j]); } } int m = 0; for (int i = 1; i <= 50; i++) { if (solve(i) > k) b[m++] = i; } if (m == 0) { printf("-1\n"); } else { for (int i = 0; i < m; i++) { if (i == 0) { printf("%d", b[i]); } else printf(" %d", b[i]); } printf("\n"); } } return 0;}
0 0
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- HDU 1498 50 years, 50 colors(最小顶点覆盖)
- HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
- 【二分图匹配(最小顶点覆盖)】hdu 1498 50 years,50 colors
- HDU 1498 50 years, 50 colors (二分图最小顶点覆盖)
- hdu 1498 50 years, 50 colors(枚举,最小顶点覆盖)
- 50 years, 50 colors 【最小顶点覆盖】
- HDU-1498-50 years,50 colors【二分匹配】【最小顶点覆盖】
- HDOJ-----1498--50 years, 50 colors二分图(最小顶点覆盖)
- hdu1498 50 years, 50 colors(最小顶点覆盖)
- hdu149850 years, 50 colors (多个最小顶点覆盖)
- HDU 1498 50 years, 50 colors 最小点覆盖
- HDU-1498 50 years, 50 colors 最小点覆盖
- HDU 1498 50 years, 50 colors(最小点覆盖,坑题)
- HDU 1498 50 years, 50 colors 最小点覆盖
- hdu 1498 50 years, 50 colors(最小覆盖点数)
- HDU 1498 50 years, 50 colors 二分图最小点覆盖(基础题)
- MacOS虚拟机安装VMware tools 在主机与虚拟机之间共享文件和剪贴板
- 第12章:functions
- 【37】String,StringBuffer,StringBuilder区别和概念
- codis功能性和可用性测试
- mysql性能优化-慢查询分析、优化索引和配置 分析
- HDU 1498 50 years, 50 colors(最小顶点覆盖)
- 欢迎使用CSDN-markdown编辑器
- VS2010中C#代码用"转到定义"或F12转到定义时,总是显示从元数据的问题
- 我的程序人生_写在产线跟线出差
- 《数据结构》使用数组实现数制的转换
- Android高效率编码-第三方SDK详解系列(三)——JPush推送牵扯出来的江湖恩怨,XMPP实现推送,自定义客户端推送
- ReadWriteLock的使用
- 论文笔记《Harvesting Discriminative Meta Objects with Deep CNN Features for Scene Classification》
- Caffe2——cifar10数据集创建lmdb或leveldb类型的数据