poj 2239 二分 最大匹配
来源:互联网 发布:淘宝买的基金如何赎回 编辑:程序博客网 时间:2024/06/06 09:25
题意:给出n个课程每周的课程安排,求最多可以上几个课。
解法:二分匹配-最大匹配
左集合,课程
右集合:课程上课时间的排序集合
/*---------------------------------- Love is more than a word. It says so much. When I see these four letters, I almost feel your touch. This is only happened since I fell in love with you. Why this word does this, I haven't got a clue. To My Goddess CY----------------------------------*/#include<iostream>#include<cstring>#include<algorithm>#include<cstdlib>#include<vector>#include<cmath>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<map>#include <stdio.h>#include <queue>#define maxn 350+5#define ull unsigned long long #define ll long long#define reP(i,n) for(i=1;i<=n;i++) #define REP(i,a,b) for(i=a;i<=b;i++) #define rep(i,n) for(i=0;i<n;i++)#define cle(a) memset(a,0,sizeof(a)) #define clehead(a) rep(i,maxn)a[i]=-1/* The time of story : ** while(1) { once upon a time, there was a mountain, on top of which there was a temple, in which there was an old monk and a little monk. Old monk was telling stories inside the temple. What was he talking about? ** } ÎûÎû (*^__^*)*/#define sci(a) scanf("%d",&a) #define scd(a) scanf("%lf",&a) #define pri(a) printf("%d",a) #define prie(a) printf("%d\n",a) #define prd(a) printf("%lf",a) #define prde(a) printf("%lf\n",a) #define pre printf("\n")#define LL(x) x<<1 #define RR(x) x<<|1#define pb push_back#define mod 90001#define PI 3.141592657const ull INF = 1LL << 61;const int inf = int(1e5)+10;const double eps=1e-5;using namespace std;struct node{ int u,v,w; int next;};bool cmp(int a,int b){ return a>b;}int n,t;vector<int>V[350];bool bmap[maxn][maxn];bool bmark[10000];int nx,ny;int cx[10000];int cy[10000];int findpath(int u){ int i,j,k; rep(i,ny){ if(bmap[u][i]&&!bmark[i]){ bmark[i]=1; if(cy[i]==-1||findpath(cy[i])) { cy[i]=u; cx[u]=i; return 1; } } } return 0;}int maxmatch(){ int i,j,k; int res(0); rep(i,nx)cx[i]=-1; rep(j,ny)cy[j]=-1; rep(i,nx){ if(cx[i]==-1){ rep(j,ny)bmark[j]=0; res+=findpath(i); } } return res;}int main(){ // freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(cin>>n) { int i,j,k; cle(bmap); int used[20][20]; cle(used); int t; rep(i,n) { V[i].clear(); sci(t); V[i].pb(t); rep(j,t) { int x,y; cin>>x>>y; V[i].pb(x); V[i].pb(y); used[x][y]=1; } } int ip=0; ny=0; nx=n; reP(i,7){ reP(j,12){ if(used[i][j]){ used[i][j]=ip++; } } } ny=ip; rep(i,n) { for(j=1;j<=2*V[i][0];j+=2) { bmap[i][used[V[i][j]][V[i][j+1]]]=true; } } cout<<maxmatch()<<endl; } return 0;}
0 0
- POJ 2239 二分最大匹配
- poj 2239 二分 最大匹配
- POJ 2239 二分图最大匹配
- POJ 2239 二分图最大匹配模版
- POJ 1274 / POJ 1469 / POJ 2239 二分图最大匹配
- POJ 2446 二分最大匹配
- poj 3020 二分最大匹配
- POJ 3057 最大二分匹配+bfs + 二分
- POJ 2239 —— 二分图最大匹配
- poj 2239 Selecting Courses 二分图最大匹配数
- poj 2239 Selecting Courses 二分图最大匹配
- Poj 2239 Selecting Courses 二分图最大匹配
- POJ 2239 Selecting Courses(二分图最大匹配)
- POJ 2239 Selecting Courses(二分图最大匹配)
- poj 2239 Selecting Courses 二分图最大匹配
- POJ 2239-Selecting Courses(二分图_最大匹配+哈希建图)
- poj 2239 Selecting Courses 【二分图最大匹配】
- POJ - 2239 Selecting Courses 二分图 最大匹配
- Setting property 'source' to 'org.eclipse.jst.jee.server:webProject' did not find a matching propert
- java备份MySQL (windows linux)
- android adb 命令发送 keyevent
- 职业规划
- 破解Xcode实现无证书真机调试(支持Xcode4.6.2)
- poj 2239 二分 最大匹配
- 多线程—生产者于消费者实例
- JS “缺少标识符 字符串或数字”错误
- 控制台下的扫雷
- Sqoop使用和参数简介
- Android分享介绍
- 错题集1.
- Django Ubuntu:Database returned an invalid value in QuerySet.dates(). 错误的解决方法
- 【成佩涛】纯属扯淡,常人别进