Solution report
Question:
I will give you a matrix of balloons in the Matrix. One to 50 colors are available for balloons. I will ask you if you can remove the existing colors within K times (K chances for each color ), colors that cannot be eliminated are output in ascending order.
Ideas:
I thought for a whole morning, and I understood the wrong question. In the past, each type had K chances of elimination, and thought it was a total of K chances of balloon elimination.
It's easy to understand, just like poj3041.
Minimum vertex overwrite. Use the least vertices to overwrite the most edges.
Color of each enumeration to see if the number of operations exceeds K.
English ....................
......................
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int k,n,m,mmap[1100][1100],vis[1100],pre[1100],num[1100];int dfs(int x,int c) { for(int i=1; i<=n; i++) { if(!vis[i]&&mmap[x][i]==c) { vis[i]=1; if(pre[i]==-1||dfs(pre[i],c)) { pre[i]=x; return 1; } } } return 0;}int main() { int i,j; while(~scanf("%d%d",&n,&k)) { memset(num,0,sizeof(num)); if(!n&&!k)break; for(i=1; i<=n; i++) for(j=1; j<=n; j++) scanf("%d",&mmap[i][j]); int ans[100]; for(int c=1; c<=50; c++) { memset(pre,-1,sizeof(pre)); for(i=1; i<=n; i++) { memset(vis,0,sizeof(vis)); num[c]+=dfs(i,c); } } int m=0,f=0; for(i=1; i<=51; i++) { if(num[i]&&num[i]>k) { ans[m++]=i; f=1; } } if(!f) { printf("-1\n"); continue; } sort(ans,ans+m); for(i=0; i<m-1; i++) { printf("%d ",ans[i]); } printf("%d\n",ans[m-1]); }}
50 years, 50 colors
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1607 accepted submission (s): 875
Problem descriptionon 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.
Inputthere 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.
Outputfor 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