Kattis - entertainmentbox 【贪心】
2024-08-24 08:17:26
思路
先将 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\n", ans);
}
最新文章
- 51Nod 1278 相离的圆
- Python的下载与安装
- Web的结构组件
- Robot Framework--10 万能的evaluate
- Uva 524 Prime Ring
- 应用python编写简单新浪微博应用(一)
- How to index email and attachments in nsf files?
- ios中怎么获得当前版本号
- [转载]Linux服务器性能评估与优化
- 封装好的PHP分页类,简单好用--在开源看到的,取回来自己用
- 关于mysql binlog日志的格式说明
- ASP.NET core1.0 EF MYSQL搭建中碰到几个问题记录
- C# 通过KD树进行距离最近点的查找.
- springboot的lombok
- vue里的样式添加之类名改动 和style改动
- windows下缩短time_wait的时间
- activemq 无法消费! consumers are alive when the messages are stuck !
- rabbitmq简单实例
- Maven 标签
- Matlab用mpeaks函数求峰值点坐标