作者: | 来源:互联网 | 2023-09-17 13:45
B- SelectingCoursesTimeLimit:1000MS MemoryLimit:65536KB 64bitIOFormat:%I64d&%I
B - Selecting Courses
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64uSubmit Status
Description
It is well known that it is not easy to select courses in the college, for there is usually conflict among the time of the courses. Li Ming is a student who loves study every much, and at the beginning of each term, he always wants to select courses as more
as possible. Of course there should be no conflict among the courses he selects.
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?
Output
For each test case, output one integer, which is the maximum number of courses Li Ming can select.
这题刚开始理解题目错了,尼玛,看到样例中1 1有几个,所以还以为是重复的呢,就只取了一个,然后就剩下(1,1),(2,2),(3,2),(3,3),然后就得出样例答案为4.。直接WA一发,然后又重新读题才发现理解错题意了,晕……
题意原来是当前课程会在那些时间上几次课,刚开始因为当前是一个结点了,然后周数与节数又有两个数据,所以想想这两个如果要想放在图论中,那么当然得把这两个数据合成一个地址……哈哈这么想着就有思路了……因为以前做过哈希方面的题,所以保存了好多哈希取址的计算函数,在实际中用得最多最高效也是最容易的就是BKDRHash哈希函数了,其计算式为:a*131+b这个就作为一个新地址存下来,也就是另一个结点……因为这个计算式已经被好多人证实过了,对于全部的(a,b),其取唯一地址的函数可以用这个计算,这个函数在实际中也是证明被用得最多的了,当然这个没有处理地址冲突,所以地址还是有bug的,但是就这水题这个式子够了……
然后有了这两个结点当然就可以做边了,匹配就是二分匹配了……
哈希不懂的可以看我的另一篇博文:http://blog.csdn.net/u011466175/article/details/17484687
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
POJ 2239 哈希取址+二分匹配,布布扣,bubuko.com