hdu 1498 50 years, 50 colors
来源:互联网 发布:监控软件 linux 排行 编辑:程序博客网 时间:2024/05/01 18:21
一道简单的最小点覆盖问题。。。
思想:
将每个点的x和y看作一条路径的两个端点。。
对于每个种类的气球。进行一次最大匹配搜索。。。
核心:
for(int i=0; i<n; i++) for(int j=0; j<n; j++) scanf("%d",&a),map[i][j]=a,num[a]++;
用num数组标记出现的气球种类:后续遍历;
代码如下:
#include<stdio.h>#include<string.h>int map[102][102];int link[102];int vis[102];int num[102];int n,k;int find(int a,int z){ for(int i=0; i<n; i++) { if(!vis[i]&&map[a][i]==z) { vis[i]=1; if(link[i]==-1||find(link[i],z)) { link[i]=a; return 1; } } } return 0;}int sum(int z){ int res=0; memset(link,-1,sizeof(link)); for(int i=0; i<n; i++) { memset(vis,0,sizeof(vis)); if(find(i,z)) res++; } return res;}int main(){ while(scanf("%d%d",&n,&k),n+k) { memset(num,0,sizeof(num)); int a; for(int i=0; i<n; i++) for(int j=0; j<n; j++) scanf("%d",&a),map[i][j]=a,num[a]++; int flag=0; for(int i=1; i<=50; i++) if(num[i]) { int t=sum(i); //printf("i-->%d t-->%d\n",i,t); if(t>k) { if(flag) printf(" "); printf("%d",i); flag=1; } } if(!flag) printf("-1"); 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
- HDU 1498 50 years, 50 colors
- hdu acm 1498 50 years, 50 colors
- HDU 1498 50 years, 50 colors
- HDU 1498 50 years, 50 colors
- 50 years, 50 colors HDU
- hdu 149850 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 最小点覆盖
- kickstart 建 LVM的方法
- [Unity3D] [Shader] 实现基于NDC的Sprite渐隐Shader
- openstack命令备忘录
- 如何测试静音检测
- 位运算的一些用途
- hdu 1498 50 years, 50 colors
- 国家统计局:去年领导干部在家时间平均增30分钟
- MVC 伪静态的实现方式
- cmd中操作命令
- 初学C++之通用工具(一)
- 2>.设两个二维数组,分别用两种方式进行初始化,并分别按照行优先(先输出第一行所有值,再输出第二行)、列优先(先输出第一列的所有值,再输出第二列)的次序输出。
- LinkedHashMap和HashMap的区别以及使用方法
- proc/sys/net/ipv4/下各项的意义
- 第4周作业-打字成绩判断程序—修改