当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Metasploit-域名上线隐藏IP
仿网易云音乐小程序-uniapp
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
手写分布式配置中心(1)
tiup update
【Valentine's Day special effects】--Canvas realizes full screen love
【idea】idea配置sql格式化
刘润直播预告 | 顶级高手,如何创造财富
STC89C52RC的P4口的应用问题
导入JankStats检测卡帧库遇到问题记录
软件质量评估的通用模型
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
标识符、关键字、常量 和变量(C语言)
What is next-generation modeling (with learning materials)
QSunSync 七牛云文件同步工具,批量上传
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
leetcode:266. 回文全排列
软件测试面试题:软件都有多少种分类?
IDEA 文件编码修改
How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer