zoukankan      html  css  js  c++  java
  • Kattis

    这里写图片描述

    这里写图片描述

    思路
    先将 N 个 电视节目 排序 根据 结束时间 ,结束的早的 排在前面

    然后 弄 K个标记 记录 结束时间
    然后 遍历一下 每次 如果能插入的话 插入到 结束时间最小的那个 队列里面去然后 每次插入后 更新答案

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <climits>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    using namespace std;
    typedef long long LL;
    
    const double PI  = 3.14159265358979323846264338327;
    const double E   = 2.718281828459;
    const double eps = 1e-6;
    
    const int INF  = 0x3f3f3f3f;
    const int maxn = 1e5 + 5;
    const int MOD  = 1e9 + 7;
    
    struct Node
    {
        int x, y;
    }q[maxn];
    
    bool comp(Node x, Node y)
    {
        return x.y < y.y;
    }
    
    int main()
    {
        int n, k;
        int ans = 0;
        scanf("%d%d", &n, &k);
        int x, y;
        for (int i = 0; i < n; i++)
            scanf("%d%d", &q[i].x, &q[i].y);
        sort(q, q + n, comp);
        vector <int> opt;
        for (int i = 0; i < k; i++)
            opt.push_back(0);
        for (int i = 0; i < n; i++)
        {
            int vis = upper_bound(opt.begin(), opt.end(), q[i].x) - opt.begin();
            if (vis)
            {
                opt.erase((vis - 1) + opt.begin());
                opt.push_back(q[i].y);
                ans++;
            }
        }
        printf("%d
    ", ans);
    }
    
    
    
  • 相关阅读:
    软件测试人员的年终绩效考核怎么应对
    收藏
    顶踩组件 前后两版
    订阅组件
    hdu 1963 Investment 完全背包
    hdu 4939 Stupid Tower Defense 动态规划
    hdu 4405 Aeroplane chess 动态规划
    cf 414B Mashmokh and ACM 动态规划
    BUPT 202 Chocolate Machine 动态规划
    hdu 3853 LOOPS 动态规划
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433255.html
Copyright © 2011-2022 走看看