zoukankan      html  css  js  c++  java
  • POJ 3988 Selecting Courses (Greedy)

    {POJ} {3988} {Selecting courses}

    Greedy Algorithm, time is fixed and just find the earlest finished courses.

    #include <iostream>
    #include <string>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <list>
    #include <algorithm>
    using namespace std;
    #define rep(a,x,y) for(a=x;a<y;++a)
    #define CLR(x,y) memset(x,y,sizeof(x))
    int n,ans;
    typedef struct{
        int a,b;
    }Node;
    bool operator<(const Node& a, const Node& b)
    {
        if(a.b == b.b)
            return a.a < b.a;
        return a.b < b.b;
    }
    int work()
    {
        int i,j,tmp;
        int a,b,k;
        bool v[500];
        Node node[500];
        while(scanf("%d",&n)) {
            if( 0 == n )
                break;
            rep(i,0,n)
                scanf("%d%d",&node[i].a,&node[i].b);
            sort(node,node+n);
            ans = 0;
            rep(i,0,5){
                rec = 0;
                tmp = 0;
                CLR(v,0);
                for( j = i; j < 1005; j += 5){
                    rep(k,0,n) {
                        if( !v[k] && node[k].a <= j && node[k].b > j ){
                            v[k] = true;
                            ++tmp;
                            break;
                        }
                    }
                }
                if( ans < tmp )
                    ans = tmp;
            }
            printf("%d\n",ans);
        }
        return 0;
    }
    int main()
    {
        work();
        return 0;
    }
    
  • 相关阅读:
    junit源码解析--测试驱动运行阶段
    junit源码解析--初始化阶段
    junit源码解析--核心类
    junit测试套件
    junit参数化测试
    junit忽略测试方法
    Junit4常用注解
    泛型技术
    在使用Java8并行流时的问题分析
    Linux 常用性能分析命令
  • 原文地址:https://www.cnblogs.com/lvpengms/p/2501362.html
Copyright © 2011-2022 走看看