当前位置:网站首页>2022杭电多校训练第三场 1009 Package Delivery
2022杭电多校训练第三场 1009 Package Delivery
2022-08-05 00:18:00 【Rain Sure】
题目链接
题目大意
给定我们 n n n个快递,每个快递有一个到达时间和最晚取快递时间,我们一次最多可以取 k k k个快递,问我们去快递站的最小次数是多少?
题解
经典的贪心题,我们应该让取快递的小车每次尽可能装满快递,所以我们去取快递的时候应该是在某个物品的最后一天取快递那天,因为那天积攒的物品应该是最多的。我们先按照快递快递到达时间排个序,然后把所有快递的最晚取货时间拿出来排个序,枚举最晚取货时间,然后根据当前积攒的货物进行操作,具体细节看代码~
代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define x first
#define y second
#define int long long
#define endl '\n'
const int inf = 1e9 + 10;
const int maxn = 100010, M = 2000010;
const int mod = 1e9 + 7;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
int h[maxn], e[M], w[M], ne[M], idx;
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, -1, 0, 1};
int cnt;
PII a[maxn];
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++;
}
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
signed main()
{
IOS;
int t; cin >> t;
while(t --)
{
int n, k; cin >> n >> k;
vector<int> ed;
for(int i = 0; i < n; i ++) {
int x, y; cin >> x >> y;
a[i] = {
x, y};
ed.push_back(y);
}
sort(a, a + n);
sort(ed.begin(), ed.end());
priority_queue<int, vector<int>, greater<int>> heap;
int res = 0, now = 0;
for(auto x : ed) {
int cnt = 0;
while(now < n && a[now].x <= x) heap.push(a[now ++].y);
while(heap.size() && heap.top() == x) cnt ++, heap.pop();
res += cnt / k;
if(cnt % k == 0) continue;
int extra = k - cnt % k;
while(heap.size() && extra -- ) heap.pop();
res ++;
}
cout << res << endl;
}
return 0;
}
边栏推荐
- 2022杭电多校 第三场 B题 Boss Rush
- MongoDB permission verification is turned on and mongoose database configuration
- Cython
- Couple Holding Hands [Greedy & Abstract]
- 2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
- 英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
- 电赛必备技能___定时ADC+DMA+串口通信
- 软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
- 软件质量评估的通用模型
- 简单的顺序结构程序(C语言)
猜你喜欢
随机推荐
matlab中rcosdesign函数升余弦滚降成型滤波器
【LeetCode】图解 904. 水果成篮
软件测试面试题:系统测试的策略有?
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
E - Many Operations (按位考虑 + dp思想记录操作后的结果
导入JankStats检测卡帧库遇到问题记录
tensor.nozero(), mask, [mask]
tiup update
【云原生--Kubernetes】Pod控制器
Huggingface入门篇 II (QA)
阅读笔记:如何理解DevOps?
Cython
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
【unity编译器扩展之模型动画拷贝】
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
统计单词(DAY 101)华中科技大学考研机试题
软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
Privacy Computing Overview
Cython








![[idea] idea configures sql formatting](/img/89/98cd23aff3e2f15ecb489f8b3c50e9.png)