当前位置:网站首页>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;
}
边栏推荐
- QSunSync Qiniu cloud file synchronization tool, batch upload
- 2022杭电多校第三场 L题 Two Permutations
- 【云原生--Kubernetes】调度约束
- 《MySQL入门很轻松》第2章:MySQL管理工具介绍
- leetcode经典例题——单词拆分
- leetcode:266. 回文全排列
- Mysql_14 存储引擎
- 在线中文姓名生成工具推荐
- leetcode:267. 回文排列 II
- #yyds dry goods inventory #Switching equipment serious packet loss troubleshooting
猜你喜欢
随机推荐
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
2022杭电多校 第三场 B题 Boss Rush
leetcode:269. 火星词典
node使用redis
Detailed explanation of common DNS resource record types
软件测试面试题:关于自动化测试工具?
Essential knowledge for entry-level 3D game modelers
找不到DiscoveryClient类型的Bean
怎样进行在不改变主线程执行的时候,进行日志的记录
QSunSync Qiniu cloud file synchronization tool, batch upload
统计单词(DAY 101)华中科技大学考研机试题
元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
GO中sync包自由控制并发的方法
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
MVCC是什么
刘润直播预告 | 顶级高手,如何创造财富


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





