当前位置:网站首页>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;
}
边栏推荐
- MAUI Blazor 权限经验分享 (定位,使用相机)
- Detailed explanation of common DNS resource record types
- 【云原生--Kubernetes】调度约束
- Cloud native - Kubernetes 】 【 scheduling constraints
- what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
- "Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
- E - Many Operations (按位考虑 + dp思想记录操作后的结果
- 在线中文姓名生成工具推荐
- 软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
- 软件开发工具的技术要素
猜你喜欢
leetcode: 266. All Palindromic Permutations
标识符、关键字、常量 和变量(C语言)
KT6368A Bluetooth certification problem_FCC and BQB_CE_KC certification or other instructions
Getting started with 3D modeling for games, what modeling software can I choose?
SQL关联表更新
【idea】idea配置sql格式化
情侣牵手[贪心 & 抽象]
Huggingface入门篇 II (QA)
【云原生--Kubernetes】Pod控制器
Privacy Computing Overview
随机推荐
Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
【LeetCode】双指针题解汇总
软件测试面试题:负载测试、容量测试、强度测试的区别?
软件测试面试题:一套完整的测试应该由哪些阶段组成?
机器学习(公式推导与代码实现)--sklearn机器学习库
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
性能测试如何准备测试数据
Some thoughts on writing
tiup status
tiup update
leetcode:266. 回文全排列
标识符、关键字、常量 和变量(C语言)
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
2022牛客多校第三场 J题 Journey
元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
Getting started with 3D modeling for games, what modeling software can I choose?
STC89C52RC的P4口的应用问题
tiup uninstall
[idea] idea configures sql formatting
gorm的Raw与scan