当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Will domestic websites use Hong Kong servers be blocked?
Cython
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
MongoDB permission verification is turned on and mongoose database configuration
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
10 种常见的BUG分类
Senior game modelers tell newbies, what are the necessary software for game scene modelers?
uinty lua 关于异步函数的终极思想
《MySQL入门很轻松》第2章:MySQL管理工具介绍
STC89C52RC的P4口的应用问题
E - Many Operations (按位考虑 + dp思想记录操作后的结果
矩阵数学原理
标识符、关键字、常量 和变量(C语言)
软件测试面试题:网络七层协仪具体?
【unity编译器扩展之模型动画拷贝】
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
canvas 高斯模糊效果
Essential knowledge for entry-level 3D game modelers
Implementation principle of golang coroutine









