50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nice, isn't it? To celebrate this meaningful day, the ACM team of HDU hold some fuuny games. Especially, there will be a game named "crashing color balloons".

There will be a n*n matrix board on the ground, and each grid will have a color balloon in it.And the color of the ballon will be in the range of [1, 50].After the referee shouts "go!",you can begin to crash the balloons.Every time you can only choose one kind of balloon to crash, we define that the two balloons with the same color belong to the same kind.What's more, each time you can only choose a single row or column of balloon, and crash the balloons that with the color you had chosen. Of course, a lot of students are waiting to play this game, so we just give every student k times to crash the balloons.

Here comes the problem: which kind of balloon is impossible to be all crashed by a student in k times.

 
Input
There will be multiple input cases.Each test case begins with two integers n, k. n is the number of rows and columns of the balloons (1 <= n <= 100), and k is the times that ginving to each student(0 < k <= n).Follow a matrix A of n*n, where Aij denote the color of the ballon in the i row, j column.Input ends with n = k = 0.
 
Output
For each test case, print in ascending order all the colors of which are impossible to be crashed by a student in k times. If there is no choice, print "-1".
 
Sample Input
1 1
1
2 1
1 1
1 2
2 1
1 2
2 2
5 4
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
3 3
50 50 50
50 50 50
50 50 50
0 0
 
Sample Output
-1
1
2
1 2 3 4 5
-1
 
Author
8600
 
Source
枚举每个点,建模,套板子;
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pi (4*atan(1.0))
  5. #define eps 1e-14
  6. #define bug(x) cout<<"bug"<<x<<" "<<endl;
  7. const int N=1e2+,M=1e6+,inf=2e9+,mod=1e9+;
  8. const ll INF=1e18+;
  9. int n,m,q;
  10. int a[N][N];
  11. int mp[N][N];
  12. int linker[N];
  13. bool used[N];
  14. bool dfs(int a)
  15. {
  16. for(int i=;i<n;i++)
  17. if(mp[a][i]&&!used[i])
  18. {
  19. used[i]=true;
  20. if(linker[i]==-||dfs(linker[i]))
  21. {
  22. linker[i]=a;
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. int hungary()
  29. {
  30. int result=;
  31. memset(linker,-,sizeof(linker));
  32. for(int i=;i<n;i++)
  33. {
  34. memset(used,,sizeof(used));
  35. if(dfs(i)) result++;
  36. }
  37. return result;
  38. }
  39. int slove(int f,int x)
  40. {
  41. int cnt=;
  42. memset(mp,,sizeof(mp));
  43. for(int i=;i<=f;i++)
  44. {
  45. for(int j=;j<=f;j++)
  46. {
  47. if(a[i][j]==x)
  48. {
  49. cnt++;
  50. mp[i-][j-]=;
  51. }
  52. }
  53. }
  54. if(cnt<=q)return ;
  55. int kill=hungary();
  56. if(kill<=q)return ;
  57. return ;
  58. }
  59. int flag[];
  60. vector<int>ans;
  61. int main()
  62. {
  63. while(~scanf("%d%d",&n,&q))
  64. {
  65. if(n==&&q==)break;
  66. ans.clear();
  67. for(int i=;i<=n;i++)
  68. {
  69. for(int j=;j<=n;j++)
  70. scanf("%d",&a[i][j]);
  71. }
  72. for(int i=;i<=;i++)
  73. {
  74. if(!slove(n,i))
  75. ans.push_back(i);
  76. }
  77. if(ans.size()==)
  78. printf("-1\n");
  79. else
  80. {
  81. printf("%d",ans[]);
  82. for(int i=;i<ans.size();i++)
  83. printf(" %d",ans[i]);
  84. printf("\n");
  85. }
  86. }
  87. return ;
  88. }

hdu 1498 50 years, 50 colors 最小点覆盖的更多相关文章

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

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

  2. hdu1498 50 years, 50 colors --- 最小点覆盖

    给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...

  3. HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)

    d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...

  4. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

  5. 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 ...

  6. HDU——1498 50 years, 50 colors

    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

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

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

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

  9. 50 years, 50 colors

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

随机推荐

  1. c# Use NAudio Library to Convert MP3 audio into WAV audio(将Mp3格式转换成Wav格式)

    Have you been in need of converting mp3 audios to wav audios?  If so, the skill in this article prov ...

  2. Python GUI--Tkinter实践

    之前写了Testlink自动执行程序,现使用Tkinter加上GUI试试,想要实现如下图功能 可以实现通过选择要执行的url及报告url自动执行用例,或可以直接写报告结果内容 因项目原因,只列出部分代 ...

  3. PHP概率算法---砸金蛋示例

    这是一个很经典的概率算法: function get_rand($proArr) { $result = ''; //概率数组的总概率精度 $proSum = array_sum($proArr); ...

  4. postgresql架构基础(转)-(1)

    PostgreSQL使用一种客户端/服务器的模型.一次PostgreSQL会话由下列相关的进程(程序)组成: 一个服务器进程,它管理数据库文件.接受来自客户端应用与数据库的联接并且代表客户端在数据库上 ...

  5. Python大数据:外部数据获取(网页抓取)

    import urllib2 as url import cookielib,StringIO,gzip,json import pandas as pd import numpy as np #定义 ...

  6. 使用pidstat查看进程资源使用情况

    简介 pidstat主要用于监控全部或指定进程占用系统资源的情况,如CPU,内存.设备IO.任务切换.线程等.pidstat首次运行时显示自系统启动开始的各项统计信息,之后运行pidstat将显示自上 ...

  7. SLF4J其实只是一个门面服务而已,他并不是真正的日志框架,真正的日志的输出相关的实现还是要依赖Log4j、logback等日志框架的。

    小结: 1.加层: 每一种日志框架都有自己单独的API,要使用对应的框架就要使用其对应的API,这就大大的增加应用程序代码对于日志框架的耦合性. 为了解决这个问题,就是在日志框架和应用程序之间架设一个 ...

  8. Java spring mvc多数据源配置

    1.首先配置两个数据库<bean id="dataSourceA" class="org.apache.commons.dbcp.BasicDataSource&q ...

  9. stark - 增、删、改

    一.效果图 二.增.删.改 知识点: 1.解决代码重用 {% include 'form.html' %} 2.自定制配置modelform 每张表,就可自定义配置 labels , widges.. ...

  10. Python开发【模块】:time、datatime

    时间模块 时间相关的操作,时间有三种表示方式: 时间戳               1970年1月1日之后的秒,即:time.time() 格式化的字符串    2014-11-11 11:11,   ...