| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 4638 | Accepted: 2009 |
Description
There are 12 classes every day, and 7 days every week. There are hundreds of courses in the college, and teaching a course needs one class each week. To give students more convenience, though teaching a course needs only one class, a course will be taught several times in a week. For example, a course may be taught both at the 7-th class on Tuesday and 12-th class on Wednesday, you should assume that there is no difference between the two classes, and that students can select any class to go. At the different weeks, a student can even go to different class as his wish. Because there are so many courses in the college, selecting courses is not an easy job for Li Ming. As his good friends, can you help him?
Input
Output
Sample Input
5 1 1 1 2 1 1 2 2 1 2 2 2 3 2 3 3 1 3 3
Sample Output
4
Source
#include<stdio.h>
#include<string.h>
int map[301][85],link[85];
bool used[85];
int gx,gy;
bool find(int t)
{
for(int i=1;i<=gy;i++)
{
if(!used[i]&&map[t][i]==1)
{
used[i]=true;
if(link[i]==-1||find(link[i]))
{
link[i]=t;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int num=0;
memset(link,-1,sizeof(link));
for(int i=1;i<=gx;i++)
{
memset(used,false,sizeof(used));
if(find(i)) num++;
}
return num;
}
int main()
{
int n,t,p,q;
while(scanf("%d",&n)!=EOF)
{
gx=n;
gy=84;
memset(map,0,sizeof(map));
for(int i=1;i<=n;i++)
{
scanf("%d",&t);
for(int j=1;j<=t;j++)
{
scanf("%d%d",&p,&q);
map[i][(p-1)*12+q]=1;
}
}
printf("%d/n",MaxMatch());
}
return 0;
}
本文介绍了一个解决大学生选课冲突问题的算法实现。该算法通过最大匹配算法确保学生能在不发生时间冲突的情况下选择尽可能多的课程。
861

被折叠的 条评论
为什么被折叠?



