zoukankan      html  css  js  c++  java
  • POJ 2239 Selecting Courses

    Selecting Courses

    Time Limit: 1000ms
    Memory Limit: 65536KB
    This problem will be judged on PKU. Original ID: 2239
    64-bit integer IO format: %lld      Java class name: Main
     
    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? 
     

    Input

    The input contains several cases. For each case, the first line contains an integer n (1 <= n <= 300), the number of courses in Li Ming's college. The following n lines represent n different courses. In each line, the first number is an integer t (1 <= t <= 7*12), the different time when students can go to study the course. Then come t pairs of integers p (1 <= p <= 7) and q (1 <= q <= 12), which mean that the course will be taught at the q-th class on the p-th day of a week.
     

    Output

    For each test case, output one integer, which is the maximum number of courses Li Ming can select.
     

    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

     
    解题:最大匹配
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 const int maxn = 310;
     6 bool e[maxn][maxn],used[maxn];
     7 int Link[maxn],m,n;
     8 bool match(int u){
     9     for(int i = 0; i < maxn; ++i){
    10         if(e[u][i] && !used[i]){
    11             used[i] = true;
    12             if(Link[i] == -1 || match(Link[i])){
    13                 Link[i] = u;
    14                 return true;
    15             }
    16         }
    17     }
    18     return false;
    19 }
    20 int main(){
    21     int x,y;
    22     while(~scanf("%d",&n)){
    23         memset(e,false,sizeof e);
    24         memset(Link,-1,sizeof Link);
    25         for(int i = 1; i <= n; ++i){
    26             scanf("%d",&m);
    27             while(m--){
    28                 scanf("%d%d",&x,&y);
    29                 e[i][12*(x-1) + y] = true;
    30             }
    31         }
    32         int ret = 0;
    33         for(int i = 1; i <= n; ++i){
    34             memset(used,false,sizeof used);
    35             if(match(i)) ++ret;
    36         }
    37         printf("%d
    ",ret);
    38     }
    39     return 0;
    40 }
    View Code
  • 相关阅读:
    leetcode每日一题(2020-06-24):16. 最接近的三数之和
    leetcode每日一题(2020-06-23):67. 二进制求和
    leetcode每日一题(2020-06-19):125. 验证回文串
    leetcode每日一题(2020-06-18):1028. 从先序遍历还原二叉树
    leetcode每日一题(2020-06-17):1014. 最佳观光组合
    leetcode每日一题(2020-06-16):297. 二叉树的序列化与反序列化
    leetcode每日一题(2020-06-14):1300. 转变数组后最接近目标值的数组和
    leetcode每日一题(2020-06-13):70.爬楼梯
    leetcode每日一题(2020-06-12):15. 三数之和
    springboot 项目中_ 利用Filter去解决跨域问题
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4853861.html
Copyright © 2011-2022 走看看