HDU 1498 50 years, 50 colors (least point coverage, pitfall)

Source: Internet
Author: User
50 years, 50 colors Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1635 accepted submission (s): 892


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
 

There is such a matrix, which contains balloons and balloons with color numbers 1-50, ask if the balloon of the same color can be removed within K times (each time ask for K chances). If the number of the balloon exceeds K, store it, and output by serial number in ascending order.


The meaning of the question is not very easy to understand, but after reading it, it will be very clear.

Minimum vertex overwrite-that is, use the least vertex to overwrite the most edges in the graph.

You can enumerate them one by one.


The one-dimensional subscript of the matrix is used as the X set, and the two-dimensional subscript is used as the y set, asking about the maximum matching of all vertices, which is not satisfied by K nature.


#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <math.h>#define init(a) memset(a,0,sizeof(a))#define PI acos(-1,0)using namespace std;const int maxn = 110;const int maxm = 100001;#define lson left, m, id<<1#define rson m+1, right, id<<1|1#define min(a,b) (a>b)?b:a#define max(a,b) (a>b)?a:bconst int N = 50010;int ma[maxn][maxn];int line[maxn],res[maxn];bool vis[maxn],bj[maxn];int k,n,m,t;int cmp(const void *a,const void *b){    return *(int *)a - *(int *)b;}int DFS(int st,int u){    for(int v = 1;v<=n;v++)    {        if(ma[u][v]== st && !vis[v])        {            vis[v] = 1;            if(line[v]==-1 || DFS(st,line[v]))            {                line[v] = u;                return 1;            }        }    }    return 0;}int K_M(int st){    memset(line,-1,sizeof(line));    int ans = 0;    for(int i = 1;i<=n;i++)    {        init(vis);        ans += DFS(st,i);    }    return ans;}int main(){    int t;    while(~scanf("%d%d",&n,&k))    {        if(n==0 && k== 0) break;        init(ma); init(res); init(bj);        for(int i = 1;i<=n;i++)        {            for(int j = 1;j<=n;j++)            {                scanf("%d",&t);                ma[i][j] = t;                if(!bj[t])                    bj[t] = 1;            }        }        int cnt,num = 0;        for(int i = 1;i<=55;i++)        {            if(bj[i])            {                 cnt = K_M(i);                 (cnt>k)?(res[num++] = i):(1);            }        }        if(num==0) puts("-1");        else        {            //sort(res,res+num);            qsort(res,num,sizeof(res[0]),cmp);            for(int j = 0;j<num-1;j++)                printf("%d ",res[j]);            printf("%d\n",res[num-1]);        }    }    return 0;}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.