hdu5090Game with Pearls(二分图匹配)
来源:互联网 发布:恶搞锁屏软件 编辑:程序博客网 时间:2024/06/06 19:03
这道题目其实应该是可以用模拟写的,但是后来发现可以用二分图来解决,就写了一发,结果一直wa了一晚上,后来发现比如说1,2,3,4,5,5,我是按值进行加边的,结果5只加了一轮边,所以匹配数无论怎么算最多也只可能是5,(本来是打算哈希一下之类的,后来发现了更好的办法),这个时候我们就不能按照权值来加边了,要用点加边,这样就能保证每个点至少加了一次
#include <iostream>#include <string.h>#include <algorithm>using namespace std;const int maxn=105;int un,vn;int g[maxn][maxn];int a[maxn];int linker[maxn*maxn];bool used[maxn*maxn];bool dfs(int u){ for(int v=1; v<=vn; v++) if(g[u][v]&&!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } return false;}int hungry(){ int res=0; memset(linker,-1,sizeof(linker)); for(int u=1; u<=un; u++) { memset(used,false,sizeof(used)); if(dfs(u)) res++; } return res;}int cmp(int x,int y){ return x<y;}int main(){ int T,n,k; cin>>T; while(T--) { memset(g,0,sizeof(g)); memset(a,0,sizeof(a)); cin>>n>>k; for(int i=1; i<=n; i++) cin>>a[i]; sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++) for(int j=0; j<=n,a[i]+j<=n; j+=k) { //g[a[i]][a[i]+j]=1;这样写是不行的,因为只把值加边,当同一个值出现了多次的时候,就会出现问题了,切记 g[i][a[i]+j]=1; } vn=n,un=n; int ans=hungry(); if(ans==n) cout<<"Jerry"<<endl; else cout<<"Tom"<<endl; } return 0;}
0 0
- hdu5090Game with Pearls(二分图匹配)
- hdoj5090Game with Pearls【二分图最大匹配】
- HDOJ 5090 Game with Pearls 二分图匹配
- hdoj 5090 Game with Pearls 【二分图最大匹配】
- HDU 5090--Game with Pearls【二分图最大匹配】
- Hdu 5090 Game with Pearls(二分匹配)
- HDU 5090 Game with Pearls(二分匹配)
- HDU 5090 Game with Pearls(二分匹配)
- 【二分匹配】 HDU 5090 Game with Pearls
- hdu 5090 Game with Pearls (二分匹配)
- HDOJ 题目5090 Game with Pearls(二分图)
- HDU ACM 5090 Game with Pearls->二分图最大匹配或?
- hdoj.5090 Game with Pearls【二分图匹配】 2015/08/14
- HDU 5090 Game with Pearls【贪心||模拟||二分匹配】
- HDU 5090 Game with Pearls(贪心, 二部图最大匹配)
- hdu 5090 Game with Pearls(最大匹配)
- hdu 5090 Game with Pearls(最大匹配)
- HDU 5090 Game with Pearls(贪心)
- 【OpenCV】反差条件下去背景
- 腾讯云下安装docker
- 去哪儿2017校园招聘笔试题——获得文件扩展名filename extension
- AndroidStudio设置package presentation
- predis
- hdu5090Game with Pearls(二分图匹配)
- 08. File & Network I/O
- platform_set_drvdata和platform_get_drvdata
- UVA 3971 Assemble -
- 常用数据类型对应字节数 32/64
- unity 脚本的执行先后顺序
- 从零开始搭建Raspberry Pi机器视觉编程环境
- Android Studio显示行数
- WinSCP 中普通用户以 root 身份登录 Linux