50 years, 50 colors
来源:互联网 发布:专心做事 知乎 编辑:程序博客网 时间:2024/05/01 09:42
50 years, 50 colors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1638 Accepted Submission(s): 894
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.
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
<span style="font-size:18px;color:#993399;">这道题的题意有点绕,刚开始一直没明白过来,求教的大神。题意是:给你两个数n和k,接下来输入n行n列的矩阵,</span>
<span style="font-size:18px;color:#993399;">每个数字代表一种气球,你每次可以扎一行或一列中的一种。k表示可以扎的次数,最后求的是最后剩的最少种数的</span>
<span style="font-size:18px;color:#993399;">气球代号。</span>
<span style="font-size:18px;color:#993399;">也就是看每一种颜色的最大匹配与k的关系,若是k小于最大匹配则输出。</span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;">#include <iostream>#include<stdio.h>#include<math.h>#include<stdlib.h>#include<string.h>using namespace std;int map[101][101],a[101][101];int vis[10001];int pre[101];int n,k;int hungary(int x){ int i; for(i=1; i<=n; i++) { if(map[x][i]==1&&vis[i]==0) { vis[i]=1; if(pre[i]==-1||hungary(pre[i])) { pre[i]=x; return 1; } } } return 0;}int main(){ int i,j,l,sum,t,b[101],flag; while(scanf("%d%d",&n,&k)!=EOF) { t=0;flag=0;//标记变量 if(n==0&&k==0) break; memset(map,0,sizeof(map)); for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { scanf("%d",&a[i][j]); } } for(i=1; i<=50; i++) { sum=0; memset(pre,-1,sizeof(pre));//因为要对每种气球求最大匹配,每次都要先初始化 for(l=1; l<=n; l++) for(j=1; j<=n; j++) { if(a[l][j]==i) map[l][j]=1; else map[l][j]=0; } for(l=1; l<=n; l++) { memset(vis,0,sizeof(vis)); sum+=hungary(l); } if(sum>k) { b[t++]=i; flag=1; } } if(flag==0) printf("-1\n"); else { for(i=0; i<t-1; i++) printf("%d ",b[i]); printf("%d\n",b[t-1]); } } return 0;}</span>
0 0
- 50 years, 50 colors
- 50 years, 50 colors
- hdu1498 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
- 6.3.5 50 years, 50 colors
- HDU 1498 50 years, 50 colors
- 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
- hdu1498 50 years, 50 colors--匈牙利算法
- maven项目 hibernate一对多注解例子
- Android adb.exe程序启动不起来
- uva 10457 Magic Car (图论好题)
- C++中的类和对象
- C宏定义中的 #,##,#@
- 50 years, 50 colors
- ***最新消息: 搬迁到自建站博客***
- 上位机Labview8.2下载与安装
- LeetCode-Multiply Strings
- php学习(一)
- 使用java搭建简单的ligerui环境
- 每日算法之四十一:Spiral Matrix II (螺旋矩阵)
- 【2428】Ubiquitous Religions SDUTOJ
- Activity启动模式