HDOJ-----1498--50 years, 50 colors二分图(最小顶点覆盖)

50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2293    Accepted Submission(s): 1292


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
输入n, k,然后一个n*n矩阵,数字代表气球,相同的数字代表一类气球,每次可以踩爆一行或一列的气球,把k次不能全部踩爆的种类从小到大输出

话说这个术语叫最小顶点覆盖,用最少的顶点覆盖最多的行列数,覆盖数就是二分图最大匹配数,不过要把模板做一点调整

用vector写的,不喜欢用矩阵

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define maxn 101
#define inf 0x3f3f3f3f
#define mes(a, b) memset(a, b, sizeof(a))
using namespace std;
int link[maxn], put[maxn];
int map[maxn][maxn];
bool vis[maxn], mark[maxn];
int n;
vector<int > edge[maxn];
bool match(int u, int val){
    for(int i = 0; i < edge[u].size(); i++){
        int v = edge[u][i];
        if(!vis[i] && v == val){//核心就在这里了,把模板的vis标记以及link的连接从edge[u][i]这个值,改为i这个列数
            vis[i] = true;      //再加一个v=val做判断,画幅图很好理解
            if(link[i] == -1 || match(link[i], val)){
                link[i] = u;
                return true;
            }
        }
    }
    return false;
}
int Getmatch(int c){//获取最大匹配
    int ans = 0;
    mes(link, -1);
    for(int i = 1; i <= n; i++){
        mes(vis, false);
        if(match(i, c)){//传入c作一个比较值
            ans++;
        }
    }
    return ans;
}
int main(){
    int t, k;
    while(~scanf("%d%d", &n, &k), k || n){
        mes(mark, false);
        for(int i = 1; i <= n; i++){
            edge[i].clear();
            for(int j = 1; j <= n; j++){
                scanf("%d", &t);
                mark[t] = true;
                edge[i].push_back(t);
            }
        }
        int cnt = 0;
        for(int i = 1; i <= 50; i++){//气球一共50种,遍历出现过的就可以了,mark标记出现
            if(mark[i] && Getmatch(i) > k){
                put[cnt++] = i;
            }
        }
        if(!cnt){
            printf("-1\n");
            continue;
        }
        for(int i = 0; i < cnt; i++){
            printf("%d%c", put[i], i == cnt-1 ? '\n' : ' ');
        }
    }
    return 0;
}

基于Spring Boot搭建的一个多功能在线学习系统的实现细节。系统分为管理员和用户两个主要模块。管理员负责视频、文件和文章资料的管理以及系统运营维护;用户则可以进行视频播放、资料下载、参与学习论坛并享受个性化学习服务。文中重点探讨了文件下载的安全性和性能优化(如使用Resource对象避免内存溢出),积分排行榜的高效实现(采用Redis Sorted Set结构),敏感词过滤机制(利用DFA算法构建内存过滤树)以及视频播放的浏览器兼容性解决方案(通过FFmpeg调整MOOV原子位置)。此外,还提到了权限管理方面自定义动态加载器的应用,提高了系统的灵活性和易用性。 适合人群:对Spring Boot有一定了解,希望深入理解其实际应用的技术人员,尤其是从事在线教育平台开发的相关从业者。 使用场景及目标:适用于需要快速搭建稳定高效的在线学习平台的企业或团队。目标在于提供一套完整的解决方案,涵盖从资源管理到用户体验优化等多个方面,帮助开发者更好地理解和掌握Spring Boot框架的实际运用技巧。 其他说明:文中不仅提供了具体的代码示例和技术思路,还分享了许多实践经验教训,对于提高项目质量有着重要的指导意义。同时强调了安全性、性能优化等方面的重要性,确保系统能够应对大规模用户的并发访问需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值