当前位置:网站首页>2022 Hangzhou Electric Multi-School Training Session 3 1009 Package Delivery
2022 Hangzhou Electric Multi-School Training Session 3 1009 Package Delivery
2022-08-05 00:22:00 【Rain Sure】
题目链接
题目大意
给定我们 n n n个快递,Each courier has an arrival time and latest pick-up time,We can take at most at a time k k k个快递,Ask us what is the minimum number of trips to the express station?
题解
经典的贪心题,We should make the trolleys that pick up the courier as full as possible each time,So when we go to pick up the courier, it should be the day to pick up the courier on the last day of an item,Because the items accumulated that day should be the most.We first sort by express delivery time,Then take out the latest pick-up time of all couriers and sort them in order,Enumerate latest pickup time,Then operate according to the current accumulated goods,具体细节看代码~
代码
#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 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
- jenkins send mail system configuration
- canvas 高斯模糊效果
- 软件测试面试题:负载测试、容量测试、强度测试的区别?
- 10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
- First, the basic concept of reptiles
- 【idea】idea配置sql格式化
- 动态上传jar包热部署
- could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
- redis可视化管理软件Redis Desktop Manager2022
猜你喜欢
10 种常见的BUG分类
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
图解 Canvas 入门
【云原生--Kubernetes】Pod控制器
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
leetcode:266. 回文全排列
leetcode: 266. All Palindromic Permutations
软件质量评估的通用模型
[LeetCode] Summary of Matrix Simulation Related Topics
KT148A voice chip ic working principle and internal architecture description of the chip
随机推荐
机器学习(公式推导与代码实现)--sklearn机器学习库
Essential knowledge for entry-level 3D game modelers
tiup telemetry
Senior game modelers tell newbies, what are the necessary software for game scene modelers?
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
Chinese and Japanese color style
tiup update
情侣牵手[贪心 & 抽象]
论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
僵尸进程和孤儿进程
软件开发工具的技术要素
About I double-checked and reviewed the About staff page, returning an industry question
ARC129E Yet Another Minimization 题解 【网络流笔记】
leetcode经典例题——单词拆分
软件测试面试题:测试生命周期,测试过程分为几个阶段,以及各阶段的含义及使用的方法?
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
软件质量评估的通用模型
软件测试面试题:一套完整的测试应该由哪些阶段组成?
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
【LeetCode】滑动窗口题解汇总