poj 2239 Selecting Courses
来源:互联网 发布:网络各种骗术 编辑:程序博客网 时间:2024/05/29 21:34
确定用二分图算法,就找好对应关系,本题对应关系为一周的所有课节N=7*12,和每一科的对应。
1 //1274,2239,2584,2536,2446 2 //http://wenku.baidu.com/view/9962910590c69ec3d5bb75da.html 贪心最大二分匹配 3 //匈牙利树和增广轨 4 5 #include <cstdio> 6 #include <cstring> 7 8 int used[610]; //是否在覆盖点中 9 10 int nmap[610][610];11 12 int path[610];//前一个13 14 int P,N;15 16 int cross(int k)17 {18 19 int i;20 for(i=1;i<=N;i++)21 {22 if(!nmap[k][i] || used[i]) continue;23 24 used[i] = 1;25 if(path[i] == -1 || cross(path[i]))26 {27 path[i] = k;28 return 1;29 }30 }31 return 0;32 }33 34 int hungray()35 {36 int i;37 int nret = 0;38 memset(path,-1,sizeof(path));39 for(i=1;i<=P;i++)40 {41 if(cross(i)) nret++;42 memset(used,0,sizeof(used));43 }44 return nret;45 }46 47 int main()48 {49 //freopen("in.txt","r",stdin);50 //freopen("out.txt","w",stdout);51 int tcase,i,j,a,b,c,z;52 N = 12 * 7;53 //scanf("%d",&tcase);54 while(~scanf("%d",&P))55 {56 memset(nmap,0,sizeof(nmap));57 for(i=1;i<=P;i++)58 {59 scanf("%d",&c);60 for(j=0;j<c;j++)61 {62 scanf("%d%d",&a, &b);63 z = (a-1)*12+b;64 nmap[i][z] = 1;65 }66 }67 printf("%d\n",hungray());68 }69 return 0;70 }
0 0
- 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
- 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 G - Selecting Courses
- POJ 2239 Selecting Courses (二分匹配)
- POJ 2239 Selecting Courses EK!匈牙利!SAP?
- C++ -- 如何取得一个给定的地址所存放的值
- poj 1258 Agri-Net
- poj 1236 Network of Schools
- g729源码分析-2-共振锋感知加权
- poj 1274 The Perfect Stall
- poj 2239 Selecting Courses
- 蓝桥杯 兰顿蚂蚁(模拟)
- hdu 1166 敌兵布阵
- hdu 1394 Minimum Inversion Number
- hdu 2795 Billboard
- OOP Class详解
- poj 2528 Mayor's posters
- poj 3225 Help with Intervals
- poj 2037 今年暑假不AC