CSU 1531 Jewelry Exhibition 二分匹配(裸
来源:互联网 发布:去除手机屏幕亮点软件 编辑:程序博客网 时间:2024/05/04 04:21
题目链接:点击打开链接
题意:
给定[0,n] * [0,m]的二维矩阵
矩阵内有k个绿点
下面k行给出绿点坐标,(保证给出的坐标都不是整数且 0 <= x <= n , 0 <= y <= m
问:
用宽度为1的刷子,一次可以把一行染色或者把一列染色
问最少要使用几次刷子
思路:
二分匹配,把所有点都映射到该点所在的方格的左下角坐标里(即舍弃小数部分)
然后就是一道经典的行列匹配,和排兵布阵一样做法。
#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cmath>#include <cstring>#include <queue>#include <set>#include <map>#include <vector>template <class T>inline bool rd(T &ret) {char c; int sgn;if(c=getchar(),c==EOF) return 0;while(c!='-'&&(c<'0'||c>'9')) c=getchar();sgn=(c=='-')?-1:1;ret=(c=='-')?0:(c-'0');while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');ret*=sgn;return 1;}template <class T>inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0');}using namespace std;typedef long long ll;typedef pair<int,int> pii;const int N = 105;const int inf = 1e8;int lef[N], pn;//lef[v]表示Y集的点v 当前连接的点 , pn为x点集的点数bool T[N]; //T[u] 表示Y集 u 是否已连接X集vector<int>G[N]; //匹配边 G[X集].push_back(Y集) 注意G 初始化bool match(int x){ // x和Y集 匹配 返回x点是否匹配成功for(int i=0; i<G[x].size(); i++){int v = G[x][i];if(!T[v]){T[v] = true;if(lef[v] == -1 || match( lef[v] )) //match(lef[v]) : 原本连接v的X集点 lef[v] 能不能和别人连,如果能 则v这个点就空出来和x连{lef[v] = x;return true;}}}return false;}int solve(){int ans = 0;memset(lef, -1, sizeof(lef));for(int i = 0; i< pn; i++)//X集匹配,X集点标号从 1-pn 匹配边是G[左点].size(){memset(T, 0, sizeof(T));if( match( i ) ) ans++;}return ans;}int n, m, point;int main(){int T; rd(T);double x, y; while(T-->0){ rd(n); rd(m); rd(point); for(int i = 0; i < N; i++)G[i].clear(); pn = n; while(point-->0){ scanf("%lf %lf", &x, &y);int X = x, Y = y;G[X].push_back(Y); }pt(solve()); puts(""); } return 0;}
0 0
- CSU 1531 Jewelry Exhibition 二分匹配(裸
- CSU-1531 Jewelry Exhibition —— 二分图匹配(最小覆盖点)
- CSU 1531 — Jewelry Exhibition
- CSU 1552( MiLLer_Rabin+二分图匹配)
- csu 1552: Friends(拉宾米勒测试+二分匹配)
- CSU 1552: Friends(素数测试+二分匹配)
- CSU 1552-Friends(大数判断素数+二分匹配)
- CSU 1552 Friends(Miller_Rabin素数测试+二分图匹配)
- CSU 1623 Inspectors(二分图最大权匹配 KM算法)(UVAlive 6879)
- CSU 1204 Rectangles (二分)
- CSU 1102 图形匹配
- CSU 1809 括号匹配问题
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- CSU 1527 Bounty Hunter dp 双调旅行商
- 熊厂实习生招聘面试经验
- Full eucalyptus 1001 hardwood core phenolic glue dynea brown film faced plywood Korinplex plywood
- 关于连接负载生成器 Load Generator 的问题
- optimize在mysql中的用法
- CSU 1531 Jewelry Exhibition 二分匹配(裸
- 【JavaScript】使用get方法提交Ajax之前对于某些符号的处理方案
- 从0开始理解正则表达式
- 内存屏障
- Fiddler (四) 实现手机的抓包
- CSU 1532 JuQueen 线段树 lazy 区间最值
- 请教:APNS的device token每个设备每个app都唯一吗
- hdu 1690 Bus System 最短路 Floyd算法。。INF一定要很大很大。。。数据类型用long long。
- UITableViewCell点击时背景颜色