博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
50 years, 50 colors
阅读量:6348 次
发布时间:2019-06-22

本文共 3732 字,大约阅读时间需要 12 分钟。

50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 137 Accepted Submission(s): 86
 
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 112 11 11 22 11 22 25 41 2 3 4 52 3 4 5 13 4 5 1 24 5 1 2 35 1 2 3 43 350 50 5050 50 5050 50 500 0
 
Sample Output
-1121 2 3 4 5-1
 
Author
8600
 
Source
“2006校园文化活动月”之“校庆杯”大学生程序设计竞赛暨杭州电子科技大学第四届大学生程序设计竞赛
 
Recommend
LL
/*给你一个n*n的格子矩阵每个格子中都存放着一种颜色的气球,现在你有k次机会,每次选择一中颜色,然后在选择一行,或者一列,将这行或这列的这种颜色的气球全部踩破,k次操作之后将没有踩破的气球安照从小到大的顺序输出,如果没有就输出-1初次思路:将颜色和边转化为二分图,然后进行二分图匹配,求最小覆盖点,也就是最大匹配,每种颜色的最大匹配的边数假设所有的边选取的k次的边都是行,或者都是列*/#include
using namespace std;int n,k;int vis[55];//记录那种颜色出现过int color;/***********************二分匹配模板**************************/const int MAXN=1000;int g[MAXN][MAXN];//编号是0~n-1的 int linker[MAXN];//记录匹配点i的匹配点是谁vector
v;bool used[MAXN];bool dfs(int color,int u)//回溯看能不能通过分手来进行匹配{ int v; for(v=1;v<=n;v++) if(g[u][v]==color&&!used[v]) //如果有这条边,并且这条边没有用过 { used[v]=true; if(linker[v]==-1||dfs(color,linker[v]))//如果这个点没有匹配过,并且能找到匹配点,那么就可以以这个边作为匹配点 { linker[v]=u; return true; } } return false; } int hungary(int color)//返回最大匹配数{ int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=1;u<=n;u++) { memset(used,0,sizeof(used)); if(dfs(color,u))//如果这个点有匹配点 res++; } return res; }/***********************二分匹配模板**************************/int main(){ //freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&k)!=EOF&&(n+k)){ memset(g,0,sizeof g); memset(vis,0,sizeof vis); v.clear(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%d",&color); if(vis[color]==0){ vis[color]=1; } g[i][j]=color; } } for(int i=1;i<=50;i++){ if(vis[i]){
//这种颜色用过了 if(hungary(i)>k)//说明这种颜色不可能被消掉 v.push_back(i); } } if(v.size()==0) printf("-1\n"); else{ for(int i=0;i

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6200889.html

你可能感兴趣的文章
Windows phone应用开发[16]-数据加密
查看>>
SQL Server 迁移数据到MySQL
查看>>
通用数据压缩算法简介
查看>>
The next Industry Standard in IT Monitoring, a python implementation Nagios like tool --- Shinken
查看>>
(笔记)找工作,该怎么进补
查看>>
div的显示和隐藏以及点击图标的更改
查看>>
(轉貼) Ubuntu將在ARM平台netbook上現身 (SOC) (News) (Linux) (Ubuntu)
查看>>
SQL注入测试工具:Pangolin(穿山甲)
查看>>
在html 的img属性里只显示图片的部分区域(矩形,给出开始点和结束点),其他部份不显示,也不要拉伸...
查看>>
程序员第二定律:量化管理在程序员身上永无可能
查看>>
ubuntu一些脚本的执行顺序
查看>>
类继承的结构
查看>>
Intel 被 ARM 逼急了
查看>>
testng + reportng 测试结果邮件发送
查看>>
神操作:如何将Vim变成一个R语言IDE
查看>>
百度亮相iDASH,推动隐私保护在人类基因组分析领域的应用
查看>>
比特币暴涨拉升至1w美元以上,说比特币崩盘的专家要失望了
查看>>
Python「八宗罪」
查看>>
你的隐私还安全吗?社交网络中浏览历史的去匿名化
查看>>
NeurIPS 2018|如何用循环关系网络解决数独类关系推理任务?
查看>>