当前位置:网站首页>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;
}
边栏推荐
- Getting started with 3D modeling for games, what modeling software can I choose?
- 统计单词(DAY 101)华中科技大学考研机试题
- 工业物联网 —— 新型数据库的召唤
- uinty lua 关于异步函数的终极思想
- 图解 Canvas 入门
- The master teaches you the 3D real-time character production process, the game modeling process sharing
- [CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
- 【Valentine's Day special effects】--Canvas realizes full screen love
- 动态上传jar包热部署
- Metasploit-域名上线隐藏IP
猜你喜欢
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
gorm联表查询-实战
Privacy Computing Overview
What is next-generation modeling (with learning materials)
node使用redis
what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
Essential knowledge for entry-level 3D game modelers
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
MongoDB permission verification is turned on and mongoose database configuration
电子行业MES管理系统的主要功能与用途
随机推荐
动态上传jar包热部署
子连接中的参数传递
QSunSync 七牛云文件同步工具,批量上传
【LeetCode】图解 904. 水果成篮
Cython
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
Cython
Three tips for you to successfully get started with 3D modeling
软件质量评估的通用模型
golang 协程的实现原理
Cloud native - Kubernetes 】 【 scheduling constraints
jenkins发送邮件系统配置
Detailed explanation of common DNS resource record types
标识符、关键字、常量 和变量(C语言)
软件开发工具的技术要素
情侣牵手[贪心 & 抽象]
leetcode: 266. All Palindromic Permutations
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
软件测试面试题:测试用例通常包括那些内容?
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32