CF822C Hacker, pack your bags!
思路:
对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可。于是可以开一个数组a[],a[i]表示所有能与i配对的区间(duration为x - i)的最小花费。计算的时候根据区间左端点由小到大依次更新就可以满足区间不重叠的限制,具体参见代码。
实现:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std; typedef long long ll;
const ll MAXN = , INF = 0x3f3f3f3f3f3f3f3f;
typedef pair<ll, ll> P;
vector<P> L[MAXN], R[MAXN];
ll a[MAXN]; int main()
{
ll n, x, l, r, c;
scanf("%I64d %I64d", &n, &x);
fill(a, a + MAXN, INF);
for (int i = ; i < n; i++)
{
scanf("%I64d %I64d %I64d", &l, &r, &c);
L[l].push_back({r - l + , c});
R[r].push_back({r - l + , c});
}
ll ans = INF;
for (int i = ; i < MAXN; i++)
{
for (auto it : L[i])
{
if (it.first >= x) continue;
ans = min(ans, a[x - it.first] + it.second);
}
for (auto it : R[i])
a[it.first] = min(a[it.first], it.second);
}
cout << (ans == INF ? - : ans) << endl;
return ;
}
CF822C Hacker, pack your bags!的更多相关文章
- CF822C Hacker, pack your bags!(思维)
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...
- CF-822C Hacker, pack your bags! 思维题
题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚 ...
- Codeforces822 C. Hacker, pack your bags!
C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心
C. Hacker, pack your bags! It's well known that the best way to distract from something is to do ...
- CodeForces 754D Fedor and coupons&&CodeForces 822C Hacker, pack your bags!
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codefroces 822C Hacker, pack your bags!
C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces 822C Hacker, pack your bags! - 贪心
It's well known that the best way to distract from something is to do one's favourite thing. Job is ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags!(更新数组)
传送门 题意 给出n个区间[l,r]及花费\(cost_i\),找两个区间满足 1.区间和为指定值x 2.花费最小 分析 先用vector记录(l,r,cost)和(r,l,cost),按l排序,再设 ...
随机推荐
- [大雾雾雾雾] 告别该死的 EFCore Fluent API
[EF Core Oracle 列名大小写问题] [EF Core Oracle column name case problem] [EF Core PostgreSql 列名大小写问题] [EF ...
- 使用Tornado实现http代理
0x00 http代理 http代理的用处非常多,市面上也有公开的代理,可是有时候为了工作须要,比方分析应用层流量.做数据訪问控制.甚至做监控等等.Tornado提供了一些非常方便的环境和API,我们 ...
- Python进阶系列之怎么写出pythonic的代码
使用 in/not in 检查key是否存在于字典中 判断某个key是否存在于字典中时,一般的初学者想到的方法是,先以列表的形式把字典所有的key返回,在判断该key是否存在于key列表中 d = { ...
- 文件权限的获取,cmd命令:Takeown
takeown /f * /a /r /d y #强制将当前目录下的所有文件及文件夹.子文件夹下的所有者更改为管理员组(administrators)命令: cacls d:documents*.* ...
- 【大数据处理架构】1.spark streaming
1. spark 是什么? >Apache Spark 是一个类似hadoop的开源高速集群运算环境 与后者不同的是,spark更快(官方的说法是快近100倍).提供高层JAVA,Scala, ...
- 手游产品经理初探(二)从营销角度看loading界面
近期開始写产品相关的专题,准备从细节入手去思考.总结一些不为人注意的细节地方. 今天给大家分享的是游戏里面都有的loading界面. 还是从几个在Facebook上排名靠前的Casino游戏的load ...
- PHP中的extract函数的用途 extract($_GET);extract($_POST)
把客户端表单中的变量名取出来 addslashes -- 使用反斜线引用字符串 extract(addslashes($_POST)); --处理POST表单 把客户端<FORM METHOD= ...
- start com.android.settings/com.android.settings.SubSettings activity
1. get class name: adb shell shell@android:/mnt/sdcard/books $ dumpsys window windows >dump.txt g ...
- Creo二次开发—内存处理
#include <ProDisplist.h> ProError ProDisplistInvalidate(ProMdl model) Invalidates the two- or ...
- kernel devel 安装与卸载
1.查看系统内核 uname -r 2.查看已安装kernel-devel uname -a ; rpm -qa kernel\* | sort 3.下载对应的rpm wget xxx/kernel- ...