题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的。

题解:对于每一种颜色建图,对于每一个点,要么横坐标被染色,要么纵坐标被染色,所以就是最小点覆盖。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N=105;
int k,m,n;
int ans[55],link[N],used[N];
int map[N][N];
bool vis[N];
vector v[N];
bool Dfs(int k){
for(int i=0;i<v[k].size();i++){
int a=v[k][i];
if(used[a]==0){
used[a]=1;
if(link[a]==-1||Dfs(link[a])){link[a]=k;return 1;}
}
}return 0;
}
int main(){
while(scanf("%d%d",&n,&k),n!=0&&k!=0){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)scanf("%d",&map[i][j]);
memset(vis,false,sizeof(vis));int cnt=0;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
if(!vis[map[i][j]]){
vis[map[i][j]]=true;
for(int t=0;t<N;t++)v[t].clear();
for(int t=1;t<=n;t++)
for(int u=1;u<=n;u++)
if(map[t][u]==map[i][j])v[t].push_back(u);
int count=0; memset(link,-1,sizeof(link));
for(int u=1;u<=n;u++){
memset(used,0,sizeof(used));
if(Dfs(u))count++;
}
if(count>k)ans[cnt++]=map[i][j];
}
if(cnt==0)puts("-1");
else{
sort(ans,ans+cnt);
for(int i=0;i<cnt-1;i++)printf("%d ",ans[i]);
printf("%d\n",ans[cnt-1]);
}
}
return 0;
}

HDU 1498 50 years, 50 colors的更多相关文章

  1. hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498 50 years, 50 colors Time Limit: 2000/1000 MS (Ja ...

  2. HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)

    50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

  3. hdu 1498 50 years, 50 colors 最小点覆盖

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. HDU——1498 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  6. Hdu 1498 二分匹配

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. hdu 1498(最小点覆盖集)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. HDU——T 1498 50 years, 50 colors

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  9. 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)

    On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...

  10. HDU 1498:50 years, 50 colors(二分图匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...

随机推荐

  1. jQuery的三种$()

    参考脚本之家“http://www.jb51.net/article/21660.htm”   $号是jQuery“类”的一个别称,$()构造了一个jQuery对象.所以,“$()”可以叫做jQuer ...

  2. pl sql项目演练--B2C商城项目

    项目学习视频下载地址:点击下载   1.注册会员及找回密码模块 }该模块主要功能有注册会员和找回密码 }注册会员:所需信息主要有:登录号.密码.真实姓名.性别.密码问题.密码答案.Email.地址.电 ...

  3. Scala io操作

    1. 读文件 scala特有的是scala.io.Source,例如: import scala.io._ Source.fromFile(“cn.scala”,”utf8”).mkString 逐行 ...

  4. google base库之simplethread

    // This is the base SimpleThread. You can derive from it and implement the // virtual Run method, or ...

  5. Linux下Apache重启遇到No space left on device错误的解决方法

      解决办法:1.输入:ipcs -s 看有没有超过5个,如果有请执行下面2的命令:2.ipcs -s | perl -ane '/^0x00000000/ && `ipcrm -s ...

  6. JSP page include taglib

    page include taglib 语法:<%@ 指令名称 属性=值 属性=值 -%> ------------------- page 1.language 默认值java 2.ex ...

  7. TextView settextcolor 无效解决方案

    viHolder.order_item_tipcolor.setBackgroundColor(context .getResources().getColor(R.color.order_xixie ...

  8. Android Log工具类

    import java.text.SimpleDateFormat; import java.util.Date; import android.util.Log; public class LogU ...

  9. ADODB 数据库Access连接

    <?php $filepath=__FILE__;//echo __FILE__;$newarray=explode("\\",$filepath);$num=count($ ...

  10. DDR、DDR2、DDR3产品区别

    DDR采用一个周期来回传递一次数据,因此传输在同时间加倍,因此就像工作在两倍的工作频率一样.为了直观,以等效的方式命名,因此命名为DDR 200 266 333 400. DDR2尽管工作频率没有变化 ...